iddober
iddober

Reputation: 1264

implicit declaration of function 'objc_lookUpClass'

I am getting this warning for the line code:

Class myClass = objc_lookUpClass([_className UTF8String]);

I am adding

#import <Foundation/NSObjCRuntime.h>
#import <objc/objc.h>

And it still don't resolve the problem

Another warning i get on this line is: "Initialization makes pointer from integer without a cast"

Upvotes: 1

Views: 1122

Answers (2)

user1421596
user1421596

Reputation: 21

You have to import this header:

#import <objc/runtime.h>

Upvotes: 0

kennytm
kennytm

Reputation: 523614

If you check the doc, you'll see that objc_lookUpClass returns an id, not a Class. To suppress the warning you either need to make myClass an id, or cast the return value to a Class:

Class myClass = (Class)objc_lookUpClass([_className UTF8String]);

BTW, there is NSClassFromString if you have an NSString.

Class myClass = NSClassFromString(_className);

Upvotes: 3

Related Questions