I have an array controller which is bound to an nstableview. I also have some nstextfields which the user populates then presses an “add” button. I want to take those fields, first_name and last_name, and use them to populate an entity. I’ll call the entity PersonEntity.
So in the delegate for the add button I get the string values for the 2 text fields, populate an entity, then add it to the array controller. I’m new to cocoa/objective-c. This seems like a straightforward thing but it appears that I cannot create an entity like I expect
PersonEntity* person
[person setFirst_name:firstName];
[person setLast_name:lastName];
[customerArray addObject:person];
It crashes saying I can’t add nil at the [customerArray addObject:customer] line. That line is my attempt to add the entity to the array controller which is bound to the tableview. What is the correct way to do something like this?
I’m not sure if PersonEntity is a Core Data Entity, but since you question is also tagged as Core Data, I’ll assume it is.
If your ArrayController (the one bound to your NSTableView), is bound to CoreData source, you don’t add objects directly to it. Instead you add it to your managedObjectContext and it will reflect on your NSTableView.
The code should look like this:
Hope this helps!
Mane