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 XibViewProtocol {} | |
| extension XibViewProtocol where Self: UIView { | |
| static func nib(_ name: String? = nil, owner: Any? = nil, bundle: Bundle = .framework) -> Self { | |
| return bundle.loadNibNamed(name ?? String(describing: self), owner: owner, options: nil)!.first as! Self | |
| } | |
| } | |
| extension UIView: XibViewProtocol {} |
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
| class ButtonSubclass: UIButton { | |
| convenience init(title: String) { | |
| self.init() | |
| self.init(type: .system) | |
| self.setTitle(title, for: .normal) | |
| } | |
| } |
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 UITableView { | |
| func reusableCell(style: UITableViewCellStyle, reuseIdentifier: String, configureBlock: ((UITableViewCell) -> Void)? = nil) -> UITableViewCell { | |
| if let cell = dequeueReusableCell(withIdentifier: reuseIdentifier) { | |
| configureBlock?(cell) | |
| return cell | |
| } | |
| return UITableViewCell(style: style, reuseIdentifier: reuseIdentifier) | |
| } | |
| } |
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
| let sessionManager: SessionManager = { | |
| let configuration = URLSessionConfiguration.default | |
| configuration.httpAdditionalHeaders = SessionManager.defaultHTTPHeaders | |
| let sessionManager = SessionManager(configuration: configuration) | |
| let oauthHandler = OAuth2Handler(accessToken: accessToken, refreshToken: refreshToken) | |
| sessionManager.adapter = oauthHandler | |
| sessionManager.retrier = oauthHandler | |
| return sessionManager | |
| }() |
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 Foundation | |
| class Object<Type> { | |
| var value: Type! { | |
| didSet { | |
| print(value) | |
| } | |
| } | |
| // init(_ value: Type) { | |
| // self.value = value // didSet not called |
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
| struct Comment { | |
| let text: String | |
| let date: Date | |
| static func make(_ text: String) -> Comment { | |
| return Comment(text: text, date: Date()) | |
| } | |
| } |
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 UIColor { | |
| convenience init(red: Int, green: Int, blue: Int) { | |
| self.init(red: CGFloat(red) / 255, green: CGFloat(green) / 255, blue: CGFloat(blue) / 255, alpha: 1) | |
| } | |
| class var red: UIColor { return UIColor(red: 255, green: 59, blue: 48) } | |
| class var orange: UIColor { return UIColor(red: 255, green: 149, blue: 0) } | |
| class var yellow: UIColor { return UIColor(red: 255, green: 204, blue: 0) } | |
| class var green: UIColor { return UIColor(red: 76, green: 217, blue: 100) } | |
| class var tealBlue: UIColor { return UIColor(red: 90, green: 200, blue: 250) } | |
| class var blue: UIColor { return UIColor(red: 0, green: 122, blue: 255) } |
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
| precedencegroup OptionalAssignmentPrecedence { | |
| associativity: right | |
| lowerThan: AssignmentPrecedence | |
| } | |
| infix operator ?= : OptionalAssignmentPrecedence | |
| public func ?=<T>(optional: inout T?, defaultValue: @autoclosure () -> T?) { | |
| if optional == nil { | |
| optional = defaultValue() | |
| } | |
| } |
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 +=<K, V>(left: inout [K : V]?, right: [K : V]?) { | |
| right?.forEach { left?[$0] = $1 } | |
| } | |
| func +<K, V>(left: [K : V]?, right: [K : V]?) -> [K : V]? { | |
| guard let left = left else { return right } | |
| guard let right = right else { return left } | |
| return left.reduce(right) { dict, pair in | |
| var dict = dict | |
| dict[pair.0] = pair.1 |