Swift Programming: getter/setter in stored property

前端 未结 5 2061
夕颜
夕颜 2020-12-28 11:35

How do I overwrite the setter of stored property in Swift?

In Obj-C, I can overwrite its setter, but Swift doesn\'t seem to be happy about getter/setters being used

5条回答
  •  滥情空心
    2020-12-28 11:49

    get and set are for computed properties (they don't have any backing store). (In my opinion, the keyword 'var' is confusing here)

    • willSet and didSet are called for an instance variable (Use didSet to override any changes)
    • set and get are purely for computed properties

提交回复
热议问题