PDA

View Full Version : Need help with CoreData and insertNewObjectForEntityForName:


HungrySeacow
2006-04-04, 23:15
Anyone here think they can help me with this problem with CoreData? I need a method that will add an object to an entity, whose contentSet is bound to another entities selection. I have created a very easy sample program that demonstrates my problem: http://www.hungryseacow.com/Personal/CoreDataTableView.zip

The Manual Add Method button for the Source managedObject works fine, However the one for the Results managedObject does not. Take a look at the methods in the __AppController.m file

- (IBAction)addResult:(id)sender
and
- (IBAction)addSource:(id)sender

Now if you look at the Results NSArrayController, you can see that it has two bindings, the contentSet is bound to the Source's selection. There must be some way to modify this method to get it to also work with the contentSet.


- (IBAction)addResult:(id)sender
{
NSLog(@"addResult called");
NSManagedObject *source;
source = [NSEntityDescription insertNewObjectForEntityForName:@"Result"
inManagedObjectContext: [self managedObjectContext]];
[[self managedObjectContext] processPendingChanges];

}


I have been stuck on this one for a few hours! Aggg!!!

Gargoyle
2006-04-05, 07:29
There are new video tutorials on developer.apple.com. The first one was about core data, have you seen them?

I can't help much more... I will learn objective-c one day.

HungrySeacow
2006-04-05, 15:44
Yes, I checked out the video tutorial, it was great. However it didn't help with my problem. But.... I don't know why I didn't think of this before! I fixed the problem. I created an IBOutlet to the NSArray Controller called resultArrayController and then sent it this message:

NSManagedObject *source;
[resultArrayController add: source];


EDIT: Sorry the solution that I had before was wrong, now it has been corrected.