in the if statement below how could i make piece1’s name be dynamic so that it checks for other pieces also which are piece1, piece2, …piece5.
I would have to make it look like something like [@”piece%d”,i] I’m just not sure what the correct way of writing this would be since i’m just starting with iOS.
for (int i = 0; i < 6; i++) {
if(CGRectContainsPoint([piece1 frame], location)){
piece1.center = location;
}
}
Something like this :
The key bits are
NSSelectorFromStringto turn a string into a selector andperformSelector:to get the object matching it.