Created
October 7, 2017 11:49
-
-
Save nakiostudio/543662179917eefe2db70cd6e1b81e5d to your computer and use it in GitHub Desktop.
Extensions you can drag onto your project if you want to keep using a custom apply operator after EasyPeasy 1.6.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import EasyPeasy | |
#if os(iOS) || os(tvOS) | |
import UIKit | |
infix operator <~ | |
/** | |
Apply operator definitions | |
*/ | |
public extension UIView { | |
/** | |
Operator which applies the attribute given to the view located | |
in the left hand side of it | |
- parameter lhs: `UIView` the attributes will apply to | |
- parameter rhs: Attribute applied to the `UIView` | |
- returns: The array of `NSLayoutConstraints` applied | |
*/ | |
@discardableResult public static func <~ (lhs: UIView, rhs: Attribute) -> [NSLayoutConstraint] { | |
return lhs <~ [rhs] | |
} | |
/** | |
Opeator which applies the attributes given to the view located | |
in the left hand side of it | |
- parameter lhs: UIView the attributes will apply to | |
- parameter rhs: Attributes applied to the UIView | |
- returns: The array of `NSLayoutConstraints` applied | |
*/ | |
@discardableResult public static func <~ (lhs: UIView, rhs: [Attribute]) -> [NSLayoutConstraint] { | |
// Apply attributes and return the installed `NSLayoutConstraints` | |
return lhs.easy.layout(rhs) | |
} | |
} | |
/** | |
Apply operator definitions | |
*/ | |
@available (iOS 9.0, *) | |
public extension UILayoutGuide { | |
/** | |
Operator which applies the attribute given to the `UILayoutGuide` | |
located in the left hand side of it | |
- parameter lhs: `UILayoutGuide` the attributes will apply to | |
- parameter rhs: Attribute applied to the `UILayoutGuide` | |
- returns: The array of `NSLayoutConstraints` applied | |
*/ | |
@discardableResult public static func <~ (lhs: UILayoutGuide, rhs: Attribute) -> [NSLayoutConstraint] { | |
return lhs <~ [rhs] | |
} | |
/** | |
Opeator which applies the attributes given to the `UILayoutGuide` | |
located in the left hand side of it | |
- parameter lhs: `UILayoutGuide` the attributes will apply to | |
- parameter rhs: Attributes applied to the `UILayoutGuide` | |
- returns: The array of `NSLayoutConstraints` applied | |
*/ | |
@discardableResult public static func <~ (lhs: UILayoutGuide, rhs: [Attribute]) -> [NSLayoutConstraint] { | |
// Apply attributes and return the installed `NSLayoutConstraints` | |
return lhs.easy.layout(rhs) | |
} | |
} | |
#else | |
import AppKit | |
infix operator <~ | |
/** | |
Apply operator definitions | |
*/ | |
public extension NSView { | |
/** | |
Operator which applies the attribute given to the view located | |
in the left hand side of it | |
- parameter lhs: `NSView` the attributes will apply to | |
- parameter rhs: Attribute applied to the `NSView` | |
- returns: The array of `NSLayoutConstraints` applied | |
*/ | |
@discardableResult static public func <~ (lhs: NSView, rhs: Attribute) -> [NSLayoutConstraint] { | |
return lhs <~ [rhs] | |
} | |
/** | |
Opeator which applies the attributes given to the view located | |
in the left hand side of it | |
- parameter lhs: NSView the attributes will apply to | |
- parameter rhs: Attributes applied to the NSView | |
- returns: The array of `NSLayoutConstraints` applied | |
*/ | |
@discardableResult static public func <~ (lhs: NSView, rhs: [Attribute]) -> [NSLayoutConstraint] { | |
// Apply attributes and return the installed `NSLayoutConstraints` | |
return lhs.easy.layout(rhs) | |
} | |
} | |
/** | |
Apply operator definitions | |
*/ | |
@available (OSX 10.11, *) | |
extension NSLayoutGuide { | |
/** | |
Operator which applies the attribute given to the `NSLayoutGuide` | |
located in the left hand side of it | |
- parameter lhs: `NSLayoutGuide` the attributes will apply to | |
- parameter rhs: Attribute applied to the `NSLayoutGuide` | |
- returns: The array of `NSLayoutConstraints` applied | |
*/ | |
@discardableResult public static func <~ (lhs: NSLayoutGuide, rhs: Attribute) -> [NSLayoutConstraint] { | |
return lhs <~ [rhs] | |
} | |
/** | |
Opeator which applies the attributes given to the `NSLayoutGuide` | |
located in the left hand side of it | |
- parameter lhs: `NSLayoutGuide` the attributes will apply to | |
- parameter rhs: Attributes applied to the `NSLayoutGuide` | |
- returns: The array of `NSLayoutConstraints` applied | |
*/ | |
@discardableResult public static func <~ (lhs: NSLayoutGuide, rhs: [Attribute]) -> [NSLayoutConstraint] { | |
// Apply attributes and return the installed `NSLayoutConstraints` | |
return lhs.easy.layout(rhs) | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment