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 ?

3
  • Does [FormRenderManager sharedInstance].formControls always return the same array, or a new autoreleased instance for each call? Commented Nov 1, 2012 at 9:11
  • I've updated my question to point out that I'm using ARC. [FormRenderManager sharedInstance].formControls will always return the same array. Commented Nov 1, 2012 at 9:14
  • thanks! Very strange in this case... I'll think about it more. Commented Nov 1, 2012 at 9:19

1 Answer 1

1

filteredArrayUsingPredicate returns an immutable array. You will have to do this:

[NSMutableArray arrayWithArray:[array filtered...]]; 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.