objective c - How to convert a method name into a String -
i´m developing little game right , want have several levels. i´m asking if it´s first time app gets launched. if it´s user start @ level1. if want start method. have methods like:
-(void)level1{}; -(void)level2{};
. . . till level 100 or so. after if got amount of times app got started want call method, fits. tried make like:
[self [nsstring stringwithstring:@"level%d", level]];
because "level" has number 1,2,3...,100. tried make level1,level2, level3, , on. error -> unexpected interface name 'nsstring': expected expression. can please me? in advance! peace!
you need use nsselectorfromstring()
:
nsstring* methodname = [nsstring stringwithformat:@"level%d", level]; sel sel = nsselectorfromstring(methodname); [self performselector:sel];
Comments
Post a Comment