cocos2d iphone - Objective-c Workaround for running intepretted code -


i'm used using eval() in languages javascript e.t.c.

in cocos2d, select level, passing "1" or "2" loadlevel.m file, level classes named "levelone" , "leveltwo" accordingly, wanted create dictionary lookup paried "1" => "levelone" e.t.c run eval on string call [mylevel node];

apparently can't use eval in ios code, how go doing this?

try using nsstringfromclass , nsclassfromstring functions.

specifically, represent classes strings in dictionary, e.g.,

[mydictionary setobject:nsstringfromclass([levelone class]) forkey:@"1"] 

then, use right level dictionary, do:

nsstring *levelasstring = [mydictionary objectforkey:@"1"]; id node = [nsclassfromstring(levelasstring) node] 

(i'm assuming +node class method)

now, pretty uncommon , odd design in cocoa. perhaps if explain more you're doing, suggest alternate design choices might better.


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -