ios – Latest XCode does not compile closure initialization for UIView

[ad_1]

I’ve added handful extension to UIView for closure initialization:

protocol ClosureInitialization: UIView {
    associatedtype View = Self

    init(_ configurationClosure: (View) -> ())
}

extension ClosureInitialization {

    init(_ configurationClosure: (Self) -> ()) {
        self.init(body: .zero)
        configurationClosure(self)
    }
}

extension UIView : ClosureInitialization {}

Due to it, I can initialize views extra simply, e.g.:

non-public lazy var myLabel = UILabel {
    $0.textual content = "Label"
    $0.textColor = .myTextColor
    $0.font = .myFont
}

After upgrading to XCode 13.3 / 13.3.1, it stopped compiling. The one error message I get is: error: Unlawful instruction: 4. What’s extra, utilizing XCode 13.2.1 every part compiles with out an error.

[ad_2]

Leave a Reply