That's because your property must match the actual ivar's class type.
A possible solution/workaround:
//Foo.h:
@interface Foo
{
NSMutableArray* mutableArray;
}
@property (readwrite, nonatomic, retain) NSArray* array;
//or manual accessor declarations, in case you're picky about wrapper-properties.
@end
//Foo.m:
@interface Foo ()
@property (readwrite, nonatomic, retain) NSMutableArray* mutableArray;
@end
@implementation
@synthesize mutableArray;
@dynamic array;
- (NSArray *)array {
return [NSArray arrayWithArray:self.mutableArray];
}
- (void)setArray:(NSArray *)array {
self.mutableArray = [NSMutableArray arrayWithArray:array];
}
@end
You're adding a private mutableArray
property in a class extension and making the public array
simply forward to your private mutable one.
With the most recent language extensions of ObjC I tend to remove the
{
NSMutableArray* mutableArray;
}
ivar block entirely, if possible.
And define the ivar thru the synthesization, as such:
@synthesize mutableArray = _mutableArray;
which will generate a NSMutableArray *_mutableArray;
instance for you.