Skip to content

Instantly share code, notes, and snippets.

@Achyut-Sagar
Created February 3, 2021 06:58
Show Gist options
  • Save Achyut-Sagar/8163c840921b3467d35edb3a3d72c9f0 to your computer and use it in GitHub Desktop.
Save Achyut-Sagar/8163c840921b3467d35edb3a3d72c9f0 to your computer and use it in GitHub Desktop.
Initilizes a property using self executing clousure.
/// Generic Property Intializer
/// - Parameters:
/// - value: Instance of Class
/// - closure: closure of property setters
/// - Returns: instance of passed class
static func configure<T>(_ value: T, using closure: (inout T) throws -> Void) rethrows -> T {
var value = value
try closure(&value)
return value
}
//USE
private let label = configure(UILabel()){
$0.text = "Enter Name"
$0.textAlignment = .center
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment