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 that it is undeclared?
    username.text = @"";

    NSManagedObject *newContacts = [NSEntityDescription insertNewObjectForEntityForName:@"Contacts" inManagedObjectContext:cxt];     //trying to replace NSEntityDescription with 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




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

微信公众号搜索 “ IT屋 ” ,选择关注