문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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;
   }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top