Lazy property initialization in Swift

后端 未结 9 1161
深忆病人
深忆病人 2020-12-18 04:25

How would you implement the following pattern in Swift?

The Container class is initialized with a JSON array that contains dictionaries. These dictionar

9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-18 04:44

    You indicate a lazy stored property by writing the @lazy attribute before its declaration.”

    @lazy var lazyVariable:String? = ""
    

    Please bear in mind, lazy property must have an initialiser.

提交回复
热议问题