NSString no 'assign', 'retain', or 'copy' attribute is specified

后端 未结 3 1840
野的像风
野的像风 2020-12-23 18:21

I\'m declaring an NSString property in a class and objective-c is complaining that:

NSString no \'assign\', \'retain\', or \'copy\' attribute is specifie
3条回答
  •  -上瘾入骨i
    2020-12-23 18:42

    Cocoa uses reference counting to manage memory. Objects with a reference count of 0 are deleted.

    • assign - does nothing to reference count simply points your variable to the data
    • retain - points your variable to data and adds 1 to reference count, data is guaranteed to be there while your variable is still alive
    • copy - makes a copy of data, points your variable at it and makes the retain count 1

    More detail here, at Apple's own documentation.

提交回复
热议问题