Search code examples
objective-cios6xcode6

IOS & Objective C - how can i resolve this error "implicit declaration of function "class_getname " is invalid in c99"?


Actually there are two errors, the first one is : "implicit declaration of function "class_getname " is invalid in c99"

The second one is : incompatible integer to pointer conversion initializing 'const char*' with an expression of type 'int'

my method is :

-(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];

....

}

Any help on how to fix this? thank you


Solution

  • You need to #import <objc/runtime.h>