if we use a property without the “retain”, what does it change? i have this example :
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
- (id)initWithCoordinate:(CLLocationCoordinate2D) coordinate;
in the .m :
-(id)initWithCoordinate:(CLLocationCoordinate2D)coord{
coordinate = coord;
return self;
}
the “retain” is normally used for the setter, isn’t it? so here, we use the setter, in initWith…, but we don’t use “retain”… any idea?
Thanks
CLLocationCoordinate2D is not an Objective C object, so attempting to send
retainandreleaseto it doesn’t make sense.This declares an assign read only property, which is the only correct thing to do for a property with a plain C type. Additionally you have said it is
nonatomicwhich means that there is no code to synchronize the property. Since the property is a struct consisting of two 64 bit values, that probably means that you can get an inconsistent result back if you read the property at the same time as some other thread is changing it.No, you don’t actually. The line
actually assigns the instance variable directly. However, this is what you want in this case. If the property was not read/write and was an Objective-C object type, it would still be assigning the instance variable directly. In that case, you’d need one of the following.
or
or
By the way, your
initis wrong. It should follow the pattern: