Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Why does NSClassFromString return nil ? As per the definition it has to return class name. How should I take care to rectify this problem? I need to instantiate a class from string and call the method, which is in the class, using the instance created.

This is how my code looks like:

id myclass = [[NSClassFromString(@"Class_from_String") alloc] init];
[myclass method_from_class];

But the method_from_class function is not being called, control is not going into it. And my code is error free. Any idea how to solve this in Objective-C?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
770 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you are trying to instantiate a class from a static library, you must add the "-ObjC" flag to the "Other Linker Flags" build setting.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...