Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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
    }           

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
159 views
Welcome To Ask or Share your Answers For Others

1 Answer

CoreData code looks good, but you are using NSManagedObject *newContacts twice, just use another variable name or remove NSManagedObject * for the second object.

Also i would recommend you to make classes for your objects to have a direct access to variables instead of [obj setValue:value forKey:@"key"];

And of course it would be nice to see the error output.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...