vds_ios/VDS/Protocols/Initable.swift
Matt Bruce 632f7498bc created static initWith for withable
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-08-22 17:43:28 -05:00

24 lines
598 B
Swift

//
// Initable.swift
// VDS
//
// Created by Matt Bruce on 7/28/22.
//
import Foundation
public protocol Initable {
init()
}
extension Withable where Self:Initable {
/// Provides a closure to configure instances inline.
/// - Parameter closure: A closure with a mutable copy of `self` as the argument.
/// - Returns: Simply returns the mutated copy of the instance after called the `closure`.
@discardableResult public static func initWith(_ closure: (_ instance: inout Self) -> Void) -> Self {
var copy = Self()
closure(&copy)
return copy
}
}