IOS和目标C - 如何解决此错误"隐式声明函数"class_getname"在c99中无效"?

sam*_*ray 1 objective-c ios6 xcode6

实际上有两个错误,第一个是:"隐式声明函数"class_getname"在c99中无效"

第二个是:不兼容的整数到指针转换使用类型'int'的表达式初始化'const char*'

我的方法是:

-(void) donneesrecoltees:(NSData *)donnees {
    NSError *erreur;
    NSNumber *lastMessage,*currentMessage;


    //int i;
    NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
    NSString *msg;

    UIAlertView *alert;

    NSDictionary *json=[NSJSONSerialization JSONObjectWithData:donnees options:0 error:&erreur];
    // Check if it's the right class to avoid error stack

    // this is the line that is causing the error
    const char* className = class_getName([json class]);

    NSString *myClass=[NSString stringWithFormat:@"%s",className];

....

}
Run Code Online (Sandbox Code Playgroud)

有关如何解决此问题的任何帮助?谢谢

Fjö*_*nir 5

你需要 #import <objc/runtime.h>