How can I get an object based from a string in Objective C?
For example
int carNumber=5;
[@"car%i",carNumber].speed=10;
//should be same as typing car5.speed=10;
Oh course, those are just made up objects, but how could I get an object based on what is in a variable.
You cannot. When your code is compiled, the names of variables will no longer be what you’ve specified.
car5is not and has never been a string.The better strategy would be to have an array of car objects and then specify the index. In C style (where
carTypeis the type of each car):In Objective-C, if your cars are objects: