Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@romanroibu
Created May 31, 2016 18:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romanroibu/8325edc8d3887136842aa0825b5c7ee8 to your computer and use it in GitHub Desktop.
Save romanroibu/8325edc8d3887136842aa0825b5c7ee8 to your computer and use it in GitHub Desktop.
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