I have two entities: Login (user id, password) and Information (title, info).
Now there is a 1 to 1 relation between them.
I need to add some information in the database unique to a user.
My code is below here:
Login *information = [NSEntityDescription insertNewObjectForEntityForName:@"Login"
inManagedObjectContext:self.managedObjectContext];
information.information.title = informationTitleTextView.text;
information.information.info_1 = information1textview.text;
information.information.info_2 = information2textview.text;
[self.managedObjectContext save:nil]; // write to database
[self.delegate savebuttontapped:self];
But It’s not Working.I don’t Know, What i am doing wrong?Any help would be appreciated.
You haven’t added an instance of
Informationto the context. Try this:Of course, if you’re going to fetch a Login object based on its attributes, you’ll want to actually store something in those attributes:
At some point in the future, you’ll probably want to fetch just the Login object that matches your criteria. Once you have that, you can get the associated information object without any trouble: