Search code examples
iosiphoneobjective-ccore-datansobject

Replace one NSObject with another and save in coredata


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


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.