Reputation: 123
I´m developing a little game right now and I want to have several levels. So i´m asking if it´s the first time the app gets launched. If it´s like that the user will start at level1. But if now i want to start another method. I have methods like:
-(void)level1{};
-(void)level2{};
. . . till level 100 or so. So after if got the amount of times the app got started i want to call a method, which fits. So i tried to make it like:
[self [NSString stringWithString:@"level%d", level]];
Because "level" has a number like 1,2,3...,100. So i tried to make it like level1,level2, level3, and so on. But for that I get an error -> Unexpected interface name 'NSString': expected expression. Can anyone please help me? Thanks in advance! Peace!
Upvotes: 0
Views: 136
Reputation: 90701
You need to use NSSelectorFromString()
:
NSString* methodName = [NSString stringWithFormat:@"level%d", level];
SEL sel = NSSelectorFromString(methodName);
[self performSelector:sel];
Upvotes: 1