Read-only properties of protocols in Swift

前端 未结 3 1475
时光取名叫无心
时光取名叫无心 2020-12-06 20:39

From the \"Learn the Essentials of Swift\" playground, there\'s an example protocol:

protocol ExampleProtocol {
    var simpleDescription: String { get }
            


        
3条回答
  •  日久生厌
    2020-12-06 21:06

    Found this and thought it may be of interest in addition to the excellent answer already provided:

    If a protocol requires a property to be gettable and settable, that property requirement cannot be fulfilled by a constant stored property or a read-only computed property. If the protocol only requires a property to be gettable, the requirement can be satisfied by any kind of property, and it is valid for the property to be also settable if this is useful for your own code.

    Excerpt From: Apple Inc. “The Swift Programming Language (Swift 2.2).” iBooks. https://itun.es/us/jEUH0.l

提交回复
热议问题