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
| protocol LoginProvider { | |
| func login() | |
| } | |
| class EmailLoginProvider: LoginProvider { | |
| var email: String | |
| var password: String | |
| init(email: String, password: String) { | |
| self.email = email | |
| self.password = password |
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
| func propertyNames(forClass: AnyClass) -> [String] { | |
| var count = UInt32() | |
| let properties = class_copyPropertyList(forClass, &count) | |
| let names: [String] = (0..<Int(count)).flatMap { i in | |
| let property: objc_property_t = properties[i] | |
| guard let name = NSString(UTF8String: property_getName(property)) as? String else { | |
| debugPrint("Couldn't unwrap property name for \(property)") | |
| return nil | |
| } | |
| return name |
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
| // MARK: - CABasicAnimation | |
| extension CABasicAnimation { | |
| /// Creates a new animation object with its `keyPath` property set to `path` and current `keyPath` value set to `fromValue`. | |
| convenience init(keyPath path: String, layer: CALayer) { | |
| self.init(keyPath: path) | |
| self.fromValue = layer.presentation()?.value(forKeyPath: path) | |
| } | |
| } |
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
| extension UIScrollViewDelegate { | |
| func scrollViewDidEndScrolling(scrollView: UIScrollView) {} | |
| func scrollViewDidEndDecelerating(scrollView: UIScrollView) { | |
| scrollViewDidEndScrolling(scrollView) | |
| } | |
| func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) { | |
| if !decelerate { |
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
| var UUID: String? { | |
| return keychain[Constants.Keychain.UUID.description] ?? { | |
| let string = UIDevice.currentDevice().identifierForVendor?.UUIDString | |
| keychain[Constants.Keychain.UUID.description] = string | |
| return string | |
| }() | |
| } |
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
| extension Optional { | |
| func unwrap(_ f: (Wrapped) -> Void) { | |
| _ = self.map(f) | |
| } | |
| } | |
| // usage: | |
| // let username: String? |
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
| extension Array where Element: _ArrayType, Element.Generator.Element: AnyObject? { | |
| func flatten() { | |
| return flatMap { $0.flatMap { $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
| @warn_unused_result | |
| func Init<T>(value: T, @noescape block: (object: T) -> Void) -> T { | |
| block(object: value) | |
| return value | |
| } |
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
| extension UInt32 { | |
| static func random(_ range: Range<UInt32>) -> UInt32 { | |
| return arc4random_uniform(range.upperBound - range.lowerBound) + range.lowerBound | |
| } | |
| } | |
| extension CGFloat { | |
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
| extension UIView { | |
| func superview<T>(of type: T.Type) -> T? { | |
| return superview as? T ?? superview.flatMap { $0.superview(of: T.self) } | |
| } | |
| } |
OlderNewer