FROM : Jonathan
DATE : Sun Jan 06 02:41:11 2008
Hi All,
This is my first post so I hop I'm doing this right!
I'm working on a Leopard app and have started to use properties. In
one of my classes I have an NSMutableArray which I have declared in my
@interface as:
@property(copy) NSMutableArray *content;
the ivar is then @synthesized in my @implentation.
in my -init method I do:
self. content = [[NSMutableArray alloc] init];
[self. content addObject:[NSString string];
But I get the an error that tells me that I'm trying to mutate an
immutable collection. Why is this, is the setter calling a -copy
method which returns an immutable copy? If so, why have this behaviour?
Which argument to the @property directive would give the same as
- (void)setContent:(NSArray *)newArray;
{
if(content != newArray) {
[content release];
content = [[NSMutableArray alloc] initWithArray:newArray];
}
}
Thanks!
DATE : Sun Jan 06 02:41:11 2008
Hi All,
This is my first post so I hop I'm doing this right!
I'm working on a Leopard app and have started to use properties. In
one of my classes I have an NSMutableArray which I have declared in my
@interface as:
@property(copy) NSMutableArray *content;
the ivar is then @synthesized in my @implentation.
in my -init method I do:
self. content = [[NSMutableArray alloc] init];
[self. content addObject:[NSString string];
But I get the an error that tells me that I'm trying to mutate an
immutable collection. Why is this, is the setter calling a -copy
method which returns an immutable copy? If so, why have this behaviour?
Which argument to the @property directive would give the same as
- (void)setContent:(NSArray *)newArray;
{
if(content != newArray) {
[content release];
content = [[NSMutableArray alloc] initWithArray:newArray];
}
}
Thanks!






Cocoa mail archive

