在尝试使用 CoreData 时,我不断收到错误消息(所有 3 个都作为注释列在代码的一侧,以便您知道它们在哪里)。由于某种原因,我无法在网上找到这些错误。我对 CoreData 很陌生,并且很想知道我做错了什么。如果有人想知道,我有这个脚本的早期版本,但它改变了太多(参见CoreData errors for simple added to database)
@synthesize username, password;
- (IBAction)saveData:(id)sender {
AppayAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSManagedObject *newContact; //Unknown type, did you mean NSManagedObjectModel?
newContact = [NSEntityDescription insertNewObjectForEntityForName:@"Contacts" inManagedObjectContext:context]; //Use of undeclared identifier NSEntityDescription. Did you mean kSecAttrDescription?
[newContact setValue:name.text forKey:@"name"];
[newContact setValue:address.text forKey:@"address"];
name.text = @"";
address.text = @"";
NSError *error;
[context save:&error]; //instance method -save not found
}