If you know that there is only 1 instance with an id
of 5, just add a break;
at the end of the if
statement after you have made your updates. This will terminate the loop iteration and is probably the most efficient.
You shouldn't worry too much about runtime performance without profiling.
To write less code, you can write the for
as:
for (MyClass *myClass in myMutableArray) {
You may want to change away from using an array for your storage if you need to access individual items often anyway.
Also, don't do:
MyClass *myClass = [[MyClass alloc] init];
Because you're needlessly creating an instance that you never use and just gets thrown away.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…