Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import Foundation
//Inspired by: https://github.com/devxoul/Then
public protocol Configurable {}
extension Configurable {
public func configure(block: (inout Self)->Void) -> () -> Self {
return {
var copy = self
block(&copy)
return copy
}
}
}
extension NSObject: Configurable {}
//MARK:- Usage
class MyController: UIViewController, UITextFieldDelegate {
let titleLabel = UILabel().configure {
$0.textColor = UIColor.greenColor()
}()
lazy var valueField2: UITextField = UITextField().configure {
$0.delegate = self
}()
lazy var refreshControl: UIRefreshControl = UIRefreshControl().configure {
$0.addTarget(self, action: #selector(refresh(_:)), forControlEvents: .ValueChanged)
}()
func refresh(sender: AnyObject) {
//Refresh UI
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.