objective-c - IOS & Objective C - 我如何解决这个错误 "implicit declaration of function "class_getname "is invalid in c99"?

标签 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];

....

}

关于如何解决这个问题的任何帮助?谢谢

最佳答案

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

关于objective-c - IOS & Objective C - 我如何解决这个错误 "implicit declaration of function "class_getname "is invalid in c99"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30025593/

相关文章:

objective-c - viewDidLayoutSubviews 相当于 UITableViewCell

objective-c - 如何检索以下处理器统计信息?

swift - Cocoapods 0.35 构建失败

ios - 正在将 Project-Swift.h 导入 Objective-C 类...找不到文件

ios - 当allowLoginUI为“NO”时,openActiveSessionWithReadPermissions不回调

ios - 使用appDelegate填充其他类的数组

iphone - 如何在 Objective-C iOS 中利用 iPhone 5 上的 ARMv7s?

objective-c - 在 iOS6 中关闭呈现的 UINavigationController

iphone - 如何在iPhone中重绘基于UIBezierpath的textview文本内容大小

swift - 如何从另一个 Swift 文件导入一个 Swift 文件?