Skip navigation.
 
mlRe: Leopard Properties and NSMutable Array
FROM : Bill Bumgarner
DATE : Sun Jan 06 02:53:59 2008

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

Related mailsAuthorDate
mlLeopard Properties and NSMutable Array Jonathan Jan 6, 02:41
mlRe: Leopard Properties and NSMutable Array Bill Bumgarner Jan 6, 02:53
mlRe: Leopard Properties and NSMutable Array Jonathan Dann Jan 6, 03:13
mlRe: Leopard Properties and NSMutable Array Bill Bumgarner Jan 6, 03:16
mlRe: Leopard Properties and NSMutable Array André Pang Jan 6, 04:10
mlRe: Leopard Properties and NSMutable Array Bill Bumgarner Jan 6, 04:43
mlRe: Leopard Properties and NSMutable Array Scott Stevenson Jan 6, 04:49
mlLeopard Properties and 'non-nil' declaration André Pang Jan 6, 05:07
mlRe: Leopard Properties and 'non-nil' declaration Scott Stevenson Jan 6, 07:18
mlRe: Leopard Properties and 'non-nil' declaration André Pang Jan 6, 07:28
mlRe: Leopard Properties and 'non-nil' declaration Scott Anguish Jan 6, 08:33
mlRe: Leopard Properties and NSMutable Array Jonathan Dann Jan 6, 12:51
mlRe: Leopard Properties and NSMutable Array Jonathan Dann Jan 6, 15:55
mlRe: Leopard Properties and NSMutable Array Jonathan Dann Jan 6, 18:57
mlRe: Leopard Properties and NSMutable Array Bill Bumgarner Jan 6, 20:05
mlRe: Leopard Properties and NSMutable Array mmalc crawford Jan 6, 20:19
mlRe: Leopard Properties and NSMutable Array Bill Bumgarner Jan 6, 20:20
mlRe: Leopard Properties and NSMutable Array Jonathan Dann Jan 6, 20:32
mlRe: Leopard Properties and NSMutable Array Jim Correia Jan 6, 20:32
mlRe: Leopard Properties and NSMutable Array Bill Bumgarner Jan 13, 20:13