This is a related question to one I posted earlier today, I was initially looking at how best to implement copyWithZone for an object that subclasses NSObject. I am pretty happy with what I have (see 001:) but wanted to ask about removing the setters (if it even matters, please say if its not really necessary).
It was pointed out to me that I could write:
newCrime->_title = [_title copyWithZone:zone];
I have two questions firstly, the -> is using C++ notation, is there an objective-c way of accessing a property of an object (without using a setter/dot notation)?
Finally, assign and strong how would I write those, I am pretty sure that assign would be:
newCrime->_coordinate = _coordinate;
but I am not sure about what to write for a strong pointer;
newCrime->_month =
.
@property(nonatomic, strong) NSString *month;
@property(nonatomic, strong) NSString *category;
@property(nonatomic, assign) CLLocationCoordinate2D coordinate;
@property(nonatomic, strong) NSString *locationName;
@property(nonatomic, copy) NSString *title;
@property(nonatomic, copy) NSString *subtitle;
.
// 001:
- (id)copyWithZone:(NSZone *)zone {
Crime *newCrime = [[[self class] allocWithZone:zone] init];
if(newCrime) {
[newCrime setMonth:_month];
[newCrime setCategory:_category];
[newCrime setCoordinate:_coordinate];
[newCrime setLocationName:_locationName];
[newCrime setTitle:_title];
[newCrime setSubtitle:_subtitle];
}
return newCrime;
}