I encountered a problem with properties when referring to the getter and setter from a sub class:
In the base class, I have a property called listItems with a custom setter:
@interface BaseList{
NSArray *_listItems;
}
@property (nonatomic, retain) NSArray *listItems;
@end
@implementation BaseList
@synthesize listItems = _listItems;
-(void)setListItems:(NSArray *)listItems
{
[_listItems release];
_listItems = [listItems retain];
//... some logic
}
@end
The sub class has a property with a more specific name for listItems, e.g. addresses:
@interface AddressList
@property (nonatomic, retain, getter = listItems, setter = setListItems:) NSArray *addresses;
@end
The addresses property is not synthesized in the implmentation of AddressList, because it should use the getter and setter of the super’s listItems property. However, after setting:
self.addresses = [NSArray array];
the property is still nil. Funny thing is, I believe this worked well with earlier versions of Xcode. I’m currently using Xcode 4.4 (4.4.1) and I’m not sure if I’m simply doing it wrong, or if some property related stuff changed in this context. I’d be very grateful if someone can tell me how to do it correctly.
Apple changed the way accessors are synthesized in Xcode 4.4. You don’t need to declare an ivar anymore and you don’t have to synthesize the accessors. You still can of course declare your own ivars and synthesizors, but since you don’t, the compiler does it for you.
You can suppress this by using
@dynamicinstead.There is a warning that you can turn on in the Build Settings called Implicit Synthesized Properties. Turn that on to temporarily get warnings about all the accessors that are synthesized for you.