FROM : Jonathan Dann
DATE : Sun Jan 06 03:13:01 2008
Thanks alot! Thought my inexperience was rearing its ugly head.
Much appreciated
On 6 Jan 2008, at 01:53, Bill Bumgarner wrote:
> On Jan 5, 2008, at 5:41 PM, Jonathan wrote:
>> 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?
>
> That is because the synthesized method sends -copy to the mutable
> array, yielding an immutable array.
>
>> 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];
>> }
>> }
>
> Which, unfortunately, is the alternative. There is an enhancement
> request already to offer a mutablecopy keyword.
>
> b.bum
DATE : Sun Jan 06 03:13:01 2008
Thanks alot! Thought my inexperience was rearing its ugly head.
Much appreciated
On 6 Jan 2008, at 01:53, Bill Bumgarner wrote:
> On Jan 5, 2008, at 5:41 PM, Jonathan wrote:
>> 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?
>
> That is because the synthesized method sends -copy to the mutable
> array, yielding an immutable array.
>
>> 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];
>> }
>> }
>
> Which, unfortunately, is the alternative. There is an enhancement
> request already to offer a mutablecopy keyword.
>
> b.bum






Cocoa mail archive

