I am trying to create a simple database table of records using Core Data and Objective-C. I understand that instances of NSManagedObject is what I store those records in, but how many entity records can I store in a single NSManagedObject? If only one, then how do I declare multiple instances of NSManagedObjects with unique identifiers for, in this example ‘entityObj’, which must be provided by the user at runtime?
In this example, MyEntity contains three NSString attributes (city, county, name). Here’s how I’m declaring an NSManagedObject.
` NSManagedObject *entityObj = [NSEntityDescription insertNewObjectForEntityForName:@”MyEntity” inManagedObjectContext:myContext];
// fill the entityObj with data
[entityObj setValue:@"Edmonton" forKey:@"city"];
[entityObj setValue:@"Canada" forKey:@"country"];
[entityObj setValue:@"Bill" forKey:@"name"];
This stores one record of data, but I need to store more of them. How can I specify the value of ‘entityObj’ at runtime? Is there a way I can store more than one of these records in a single NSManagedObject? Intuitively, I’m thinking I might be able to make my NSManagedObject an array of myEntity records. `
Michael Guy Lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.