What is the difference between these two?
@property (nonatomic, retain)
@property (nonatomic, copy)
What is the other type like this?
What is the difference between these two?
@property (nonatomic, retain)
@property (nonatomic, copy)
What is the other type like this?
Using retain
is equivalent to this method:
- (void)setMyObject:(id)object {
myObject = [object retain];
}
Using copy
is like this:
- (void)setMyObject:(id)object {
myObject = [object copy];
}
The main difference is that there are now two copies of the same object. Now, if you change an instance variable in your class (such as changing @"A"
to @"B"
), the original object will stay intact (it will still be @"A"
).
As a general rule, use:
@property(nonatomic, copy)
..for NSString properties and this for all other object properties:
@property(nonatomic, retain)