I get a null class with NSClassFromString
I have the same code shared by 2 apps, and depending on the current app a different class is used.
className is the string which can be "PrefixClass1" or "PrefixClass2" (and it is correct for both apps, I've checked in the debugger).
However currentClass is null for app2. (It perfectly works for app1)
NSString *className = [NSString stringWithFormat:@"Prefix%@", [[NSApp delegate] applicationName]];
Class currentClass = NSClassFromString(className);
This means is null right ? http://c开发者_如何学运维l.ly/AYSn
thanks
1.) check you are really using the right class name and NSString (@"class2" Syntax)
2.) add the "-all_load" linker flag to your build settings (if linker finds no references, the class might not be loaded into the runtime)
I've solved by adding the .m file to the target > Compile Sources... Since I had many targets, xCode didn't know where to put it.
精彩评论