Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

HungrySeacow

macrumors regular
Original poster
Jan 11, 2006
137
1
West Palm Beach
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. Right now I have:
Code:
NSManagedObject *source;
source = [NSEntityDescription insertNewObjectForEntityForName:@"secondEntity"
             inManagedObjectContext: [self managedObjectContext]];
Unfortunately, this doesn't work because it is bound to the contentSet of another entity.
 

HungrySeacow

macrumors regular
Original poster
Jan 11, 2006
137
1
West Palm Beach
OK, I have created a 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.

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

HungrySeacow

macrumors regular
Original poster
Jan 11, 2006
137
1
West Palm Beach
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:
Code:
	NSManagedObject *source;
	[resultArrayController add: source];

EDIT: Sorry the solution that I had before was wrong, now it has been corrected.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.