Created
February 3, 2021 06:58
-
-
Save Achyut-Sagar/8163c840921b3467d35edb3a3d72c9f0 to your computer and use it in GitHub Desktop.
Initilizes a property using self executing clousure.
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
/// 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