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

Chirone

macrumors 6502
Original poster
Mar 2, 2009
279
0
NZ
following the apple tutorial about core data (http://developer.apple.com/document...Paste.html#//apple_ref/doc/uid/TP40002833-SW6) i tried to naively extend this to copy the relationship by adding the key of the relationship to the keysToBeCopied array

the output window told me i have to implement an encodeWithCoder method
so i did.
it looked something a little like this:
Code:
- (void)encodeWithCoder:(NSCoder *)c {
	[c encodeObject:self.title forKey:@"title"];
}

- (id) initWithCoder: (NSCoder *)c {
	self = [super init];
	if(self) {
		self.title = [c decodeObjectForKey:@"title"];
	}
	return self;
}
it then complained saying it couldn't find the method setTitle.. so i changed title from dynamic to synthesize and made an instance variable
then it complained at me again saying i was making an illegal attempt to establish relationships between different contexts

any idea how this is done? This is a to-one relationship that i was trying to copy but i'll also want to copy for to-many relationships

should i just add the first object to the pasteboard and when it gets pasted just make copies of the objects it's related to? is that efficient?
 
should i just add the first object to the pasteboard and when it gets pasted just make copies of the objects it's related to? is that efficient?

If you have to copy between contexts (e.g. different documents), then as far as I know you have no other option than copying the individual objects and re-establishing the relationships. Just copying it won't work, I am afraid.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.