以下の内容はhttps://giarrium.hatenablog.com/entry/2021/10/21/200749より取得しました。


125日目

日記

相変わらずめんどくさがってご飯を炊いてないので今日もうどん.

今日書いたコード

Specifically, if a failable initializer delegates to an initializer that fails and returns nil, then the initializer that delegated also fails and implicitly returns nil. https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_union-style-enum-case

class Super {
    var superProp: String

    init?(_ str: String) {
        if str.isEmpty {
            return nil
        }

        superProp = str
    }
}

class Sub: Super {
    var prop: String

    init?() {
        prop = "hoge"

        super.init("")
    }

    convenience init?(isHoge: Bool) {
        self.init()
    }
}

print(Sub()) // nil
print(Sub(isHoge: false)) // nil

感想

そういえばSwift イニシャライザ大全みたいなタイトルの本を読むって言っていたのを思い出した.




以上の内容はhttps://giarrium.hatenablog.com/entry/2021/10/21/200749より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14