Dealing with properties, ivars, and custom accessor methods

47 Views Asked by At

This question arose from this Encapsulating Data guide from Apple

It is really bothering me, and I want to get some insights on it. On the section You Can Implement Custom Accessor Methods, the guide does this:

@property (readonly) NSString *fullName;
- (NSString *)fullName {
     return [NSString stringWithFormat:@"%@ %@", self.firstName, self.lastName];
}

Why create a property to do this? Isn't just the method enough? And more importantly: the property fullName is by default atomic. The getter completely desregards this.

It looks to me custom getters/setters are a terrible thing to do, because they bypass all the property's modifiers. But the guide goes and tells people to do it. What am I missing here?

0

There are 0 best solutions below