Question

I am trying to update a NSObject class value I have in coredata however I am not sure how to just update the whole object. This is what I am trying to do

for (Items *item in mutableArrayOfSet) {
        if ([updatedItem.rowID isEqualToString:item.rowID]) {

            item = updatedItem;
   }
}

item is my none upated Item and updatedItem is of the same NSObject class type which I am trying to use to overwrite the current item in the set... however this line of code

item = updatedItem;

is giving an error.

Fast enumeration variables can't be modified in ARC by default; declare the variable __strong to allow this

Was it helpful?

Solution

item = updatedItem;

This is just setting the value of the iteration variable, it doesn't change anything about mutableArrayOfSet.

What you should do is to create a set of changes while you iterate and then save those changes into the source object after the iteration is complete.

OTHER TIPS

What you can do is NOT using fast ennumeration. Use a normal for loop:

for (int i=0; i<mutableArrayOfSet.length; i++)
{
     item = [mutableArrayOfSet objectAtIndex:i];
     ....
     [mutableArrayOfSet replaceObjectAtIndex:i withObject:updatedItem];
}

Why not to do what you are suggested by compiler?

for (__strong Items *item in mutableArrayOfSet) {
        if ([updatedItem.rowID isEqualToString:item.rowID]) {

            item = updatedItem;
   }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top