im getting a warning using objectFromJSONData

2019-09-07 03:31发布

my objective C app compiles successfully, but i get an Xcode warning:

Instance method '-objectFromJSONData' not found (return type defaults to 'id')

on this line:

NSDictionary *userInfo = [data objectFromJSONData];

How can i get rid of that warning?

2条回答
何必那么认真
2楼-- · 2019-09-07 03:51

When you make a custom class or use a class built outside of apple, you need to import the headers for the framework or class you are using. This allows the compiler to cross check return types and so forth.

When you attempt to send valid messages (but the compiler is unaware of) you will get that warning. The code should run and work with the warning there, but I am glad you want to get rid of the warning.

in the same .m file as the code you posted... near the top... add

#import "JSONKit.h"
查看更多
做个烂人
3楼-- · 2019-09-07 03:52

You need to #import the header file where that method is declared. And you need to make sure that data is of a class for which the method is defined.

查看更多
登录 后发表回答