views:

122

answers:

1

I have a simple UITableView (with 1 section), my dataSource is a NSMutableArray of NSMutableDictionaries. I'm trying to change the value of one of the keys inside a dictionnary, but I'm getting the "mutable method sent to immutable object".

[[mutableArray objectAtIndex:0] setValue:@"hello" forKey:@"test"];

Like I said, both the array and dictionary are mutable and allocated. Any idea why I'm getting the error?

A: 

I suspect that the mutable dictionary is not really mutable and/or a dictionary. Notice that below only the dict is mutable:

NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionaryWithCapacity:10];
NSArray *array = [NSArray arrayWithObject:mutableDictionary];

    [[array objectAtIndex:0] setValue:@"hello" forKey:@"test"];

NSLog(@"array:      %@", array);

produces:

2009-09-21 07:54:44.639 test[4262:a0f] array:      (
        {
        test = hello;
    }
)
zaph