【问题标题】:Incompatible pointer types initializing 'NSEntityDescription *' with an expression of type '__kindof NSManagedObject * _Nonnull'使用“__kindof NSManagedObject * _Nonnull”类型的表达式初始化“NSEntityDescription *”的不兼容指针类型
【发布时间】:2016-04-09 21:13:08
【问题描述】:

一切正常,但我收到此通知

并尝试搜索以找到解决方案,但没有运气

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
NSManagedObjectContext *context = appDelegate.managedObjectContext ;
NSString *title = [[Picker delegate]pickerView:Picker titleForRow:[Picker selectedRowInComponent:1] forComponent:1];

NSEntityDescription *entity = [NSEntityDescription insertNewObjectForEntityForName:@"History" inManagedObjectContext:context];

【问题讨论】:

    标签: xcode core-data nsentitydescription


    【解决方案1】:

    在这一行:

    NSEntityDescription *entity = [NSEntityDescription insertNewObjectForEntityForName:@"History" inManagedObjectContext:context];
    

    您调用的方法返回一个NSManagedObject 的实例。您将其分配给NSEntityDescription 类型的变量。这就是消息告诉您的内容。

    【讨论】:

    • 那么如何声明NsEntityDescription
    • 您可以在NSManagedObjectModel 中查找它,但这很少有必要或有用。你想在这里做什么?看起来您想要创建实体的新实例。如果是这样,那么您在该行使用错误的变量类型 except 做的一切都是正确的。该行创建了一个NSManagedObject,这就是您想要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-04
    • 2020-11-17
    相关资源
    最近更新 更多