I’m still new to Objective-C and having some difficulties trying to figure out the appropriate way to use assign, retain, copy, strong, etc. when setting a property.
For example, I have the following types declared – how should I be setting the properties?
@property (nonatomic, ??) NSMutableArray *myArray
@property (nonatomic, ??) NSString *myString
@property (nonatomic, ??) UIColor *myColor
@property (nonatomic, ??) int *myIn
@property (nonatomic, ??) BOOL *myBOOL
Thanks….
To reiterate, it does depend on context. In an non-ARC situation:
The copy on myArray is to prevent modification by another “owner” of the object you set. In an ARC project, things change a bit:
The change is primarily to myColor in your situation. You wouldn’t use
retainas you aren’t managing reference counting directly. Thestrongkeyword is a way of asserting “ownership” of the property and similar toretain. An additional keyword is also provided,weak, that would typically be used in place of assign for object types. Apple’s common example of aweakproperty is for delegates. I’d recommend going through the Transitioning to ARC Release Notes in addition to the Memory Management Guide a time or two as there is more nuance than can easily be covered in an SO post.