How are optional values implemented in Swift?

前端 未结 4 443
广开言路
广开言路 2020-12-30 01:21

I wonder how the value types in Swift (Int, Float...) are implemented to support optional binding (\"?\"). I assume those value types are not allocated on the heap, but on t

4条回答
  •  旧时难觅i
    2020-12-30 02:00

    Optionals are implemented as enum type in Swift.

    See Apple's Swift Tour for an example of how this is done:

    enum OptionalValue {
        case None
        case Some(T)
    }
    

提交回复
热议问题