0

For some reason I am unable to assign an object which I retrieve from a mutable array

UPDATE: Note that I'm using ARC

Here is the code:

id<Control> control = [formControlUtils getControlWithId:@"123"];
// Here control.controlValue is "Old value"
control.controlValue = @"New value";
// Even after assigning a new value to the property the value is still "Old value"

- (id<Control>)getControlWithId:(NSString *)controlId {
id<Control> control = nil;

for (NSArray *array in [FormRenderManager sharedInstance].formControls)
{
    //[FormRenderManager sharedInstance].formControls is a mutable array, so is the nested arrays
    control = [[array filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"controlId = %@", controlId]] lastObject];

    if (control)
        break;
}

return control;
}

As you can see in my code comments above, whenever a assign a new value to control.controlValue the old value still persists.

Why is that? Do I perhaps miss something fundamental here or is it due to the fact that I work against a protocol <id>Control control ?

4

1 に答える 1

1

filteredArrayUsingPredicate不変の配列を返します。これを行う必要があります:

[NSMutableArray arrayWithArray:[array filtered...]]; 
于 2012-11-01T09:59:20.977 に答える