Re: Copy managed object between contexts?
Re: Copy managed object between contexts?
- Subject: Re: Copy managed object between contexts?
- From: mmalcolm crawford <email@hidden>
- Date: Sat, 13 Aug 2005 17:50:42 -0700
On Aug 13, 2005, at 5:40 PM, Jim Correia wrote:
But you can write generic code once, and then use it over and over
again. So it is only manual the first time :-)
@interface NSManagedObject(CopyAdditions)
- (void)copyAttributesFromObject:(NSManagedObject *)object
{
NSArray *attributeKeys = [[self entity] attributeKeys];
NSEnumerator *enumerator = [attributeKeys objectEnumerator];
NSString *attributeName = nil;
while (nil != (attributeName = [enumerator nextObject]))
{
[self setValue: [object valueForKey: attributeName] forKey:
attributeName];
}
}
@end
It would be easier to use key-value coding -- see <http://
developer.apple.com/documentation/Cocoa/Conceptual/ModelObjects/
Articles/moCopying.html#//apple_ref/doc/uid/TP40002137>, and also
<http://developer.apple.com/documentation/Cocoa/Conceptual/
NSPersistentDocumentTutorial/05_CopyAndPaste/chapter_6_section_2.html>.
mmalc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden