0

can I do this?

[array enumerateUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){
    if (idx > 1)
    {
        NSUInteger previous1 = [array objectAtIndex: idx - 1].value;
        NSUInteger previous2 = [array objectAtIndex: idx - 2].value;
        obj.value = previous1 + previous2;
    }
}];

is it safe to do this? I am not adding/removing objects in array(or mutable array) inside enumeration block, I am just getting/changing value of object in other idx.

Thanks

4

1 回答 1

0

That is OK, except that you have to cast your objects to the right type before you can use the dot syntax to get to the value property.

于 2012-08-15T16:52:06.807 回答