Skip to content

Instantly share code, notes, and snippets.

@khanlou
Created April 7, 2018 23:32
Show Gist options
  • Save khanlou/a00714d9595c1e78199a49dc67a05ffe to your computer and use it in GitHub Desktop.
Save khanlou/a00714d9595c1e78199a49dc67a05ffe to your computer and use it in GitHub Desktop.
import Foundation
import UIKit
public protocol Configure {}
extension Configure {
/// Makes it available to set properties with closures just after initializing.
///
/// let frame = UIView().configure {
/// $0.backgroundColor = .red
/// }
public func configure(_ block: (inout Self) -> Void) -> Self {
var copy = self
block(&copy)
return copy
}
}
extension NSObject: Configure {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment