I have an array containing various instances of MyClass
, which has four properties: int id
, int valueA
, int valueB
, and int valueC
. On occasion, I need to modify a property for a specific instance (for this example let's say it is the one with id
equal to 5
).
Currently I do it like this:
MyClass *myClass = [[MyClass alloc] init];
for (int i = 0; i < [myMutableArray count]; i++)
{
myClass = [myMutableArray objectAtIndex:i];
if(myClass.id == 5)
{
myClass.valueA = 100;
myClass.valueB = 200;
myClass.valueC = 300;
[myMutableArray replaceObjectAtIndex:i withObject: myClass];
}
}
Is there a better (I am hesitant to say more efficient) way of doing this?
See Question&Answers more detail:os