I keep getting error messages (which all 3 are listed as comments on the side of the code so that you know where they are) while trying to utilize CoreData. I can’t find these errors online for some reason. I am very new to CoreData and very interested to find out what I am doing wrong. And if anybody is wondering, I had an earlier version of this script, but it changed too much (see CoreData errors for simple adding 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
}
You need to create a Managed Object Class for each entity. Also to get the Appdelegate I don’t see that you are including the header file nor do I see the header file for the managed object class. These are both needed for your application to be able to access the context and the Managed Objects.