Prior to ARC being introduced when I wanted to assign a value to a property using init (or initWith) I just used retain (as a consequence of not wanting to use a property setter inside init).
// Pre ARC using retain
// @property (nonatomic, retain) DataModel *dataModel;
// @synthesize dataModel = _dataModel;
- (id)initWithDataModel:(id)newModel {
self = [super init];
if(self) {
_dataModel = [newModel retain];
}
return self;
}
With ARC (again without using a setter) is this the correct way to assign newModel to the dataModel property? My guess is that the compiler (using ARC) will see that the property is defined as strong and correctly set the property. I am curious if this is right?
// Using ARC
// @property (nonatomic, strong) DataModel *dataModel;
// @synthesize dataModel = _dataModel;
- (id)initWithDataModel:(id)newModel {
self = [super init];
if(self) {
_dataModel = newModel;
}
return self;
}