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

IPhone IT屋
问 题

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

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
    }           

}
解决方案

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.

本文地址:IT屋 » CoreData errors for simple adding to database

问 题

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



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



   - (IBAction)saveData:(id)sender {
NSManagedObjectContext * cxt = [self managedObjectContext]; //实例方法managedObjectContext未找到
NSManagedObject * newContacts = [NSEntityDescription insertNewObjectForEntityForName:@“Contacts”inManagedObjectContext:cxt];
[newContacts setValue:self.username.text forKey:@“username”]; // insert NSManagedObjectModel而不是NSManagedObject ...声称它是未声明的?
username.text = @“”;

NSManagedObject * newContacts = [NSEntityDescription insertNewObjectForEntityForName:@“Contacts”inManagedObjectContext:cxt]; //试图用KSecAttrDescription替换NSEntityDescription ...声明它是未声明的
[newContacts setValue:self.password.text forKey:@“password”];
password.text = @“”;

NSError * err;
if(![cxt save:& err]){
NSLog(@“发生错误:%@”,[err localizedDescription]); //实例方法-save not found
}

}

解决方案

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


本文地址:IT屋 » CoreData错误,用于简单添加到数据库