CoreData错误,用于简单添加到数据库 [英] CoreData errors for simple adding to database

查看:849
本文介绍了CoreData错误,用于简单添加到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:我想要找出的错误消息在代码的右侧作为注释!!!

The error messages that I am trying to figure out are on the right side of the code listed as comments!!!

Xcode不断尝试建议替代并拒绝让我建立。 3在代码的右侧的注释标签中列出。他们的意思是什么?我非常新的使用核心数据,真的希望看到我做错了,只是使用用户名作为例子(因为我知道我不应该这样做)。

Xcode keeps trying to suggest alternatives and refusing to let me build. The 3 are listed in comment tags on the right side of the code. What do they mean? I am very new to using core data and really hoping to see what I am doing wrong, just using username as an example (as I know I shouldn't be doing so)!

- (IBAction)saveData:(id)sender {
    NSManagedObjectContext *cxt = [self managedObjectContext];       //instance method managedObjectContext not found
    NSManagedObject *newContacts = [NSEntityDescription insertNewObjectForEntityForName:@"Contacts" inManagedObjectContext:cxt];
    [newContacts setValue:self.username.text forKey:@"username"];          //insert NSManagedObjectModel instead of NSManagedObject...claims that it is undeclared?
    username.text = @"";

    NSManagedObject *newContacts = [NSEntityDescription insertNewObjectForEntityForName:@"Contacts" inManagedObjectContext:cxt];     //trying to replace NSEntityDescription with KSecAttrDescription...claims that it is undeclared      
    [newContacts setValue:self.password.text forKey:@"password"];
    password.text = @"";

    NSError *err;
    if (![cxt save:&err]) {
        NSLog(@"An error has occured: %@", [err localizedDescription]);      //Instance Method -save not found
    }           

}


推荐答案

解决了!然而,这是从这个问题的以前的答案谁删除了他们自己,所以我给这个未知的人的信用。如果任何人以后有这个错误,点击你的核心data.xcdatamoldeld,然后单击菜单栏上的编辑器部分(桌面),然后单击设置NSManagedObject子类并添加它们。它应该工作。

Solved it! However, it was from a previous answer for this question who removed them self, so I'm giving the credit to that unknown person. If anybody has this error in the future, click on you core data.xcdatamoldeld, then click on the Editor section on your menu bar (of your desktop), then click set NSManagedObject Subclass and add them. It should work then.

这篇关于CoreData错误,用于简单添加到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆