Does @property copy in combination with readonly make sense?

前端 未结 4 2225
野的像风
野的像风 2020-12-15 17:05

If I understand this correctly, copy enforces the setter to create a copy of the object passed in. However, if I use it together with readonly, the

4条回答
  •  星月不相逢
    2020-12-15 17:15

    According to Apple's documentation (which I've linked here for you):

    copy
    Specifies that a copy of the object should be used for assignment.

    The previous value is sent a release message.

    The copy is made by invoking the copy method. This attribute is valid only for object types, which must implement the NSCopying protocol.

    So yes, you're correct... readonly creates a getter method and copy would be effectively ignored, since there's no setter method that does assignment.

提交回复
热议问题