• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Copy managed object between contexts?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Copy managed object between contexts?


  • Subject: Re: Copy managed object between contexts?
  • From: Jim Correia <email@hidden>
  • Date: Sat, 13 Aug 2005 20:58:17 -0400

On Aug 13, 2005, at 8:50 PM, mmalcolm crawford wrote:

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

Well to be pedantic, I am using KVC, just in a loop :-).

But your point is taken - using the dictionary based methods simplifies the code.

- (void)copyAttributesFromObject:(NSManagedObject *)object
{
NSDictionary *values = [object dictionaryWithValuesForKeys: [[self entity] attributeKeys]];


    [self setValuesForKeysWithDictionary: values];
}

Jim
_______________________________________________
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


References: 
 >Copy managed object between contexts? (From: Colin Cornaby <email@hidden>)
 >Re: Copy managed object between contexts? (From: mmalcolm crawford <email@hidden>)
 >Re: Copy managed object between contexts? (From: Colin Cornaby <email@hidden>)
 >Re: Copy managed object between contexts? (From: mmalcolm crawford <email@hidden>)
 >Re: Copy managed object between contexts? (From: Colin Cornaby <email@hidden>)
 >Re: Copy managed object between contexts? (From: Jim Correia <email@hidden>)
 >Re: Copy managed object between contexts? (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: Re: Copy managed object between contexts?
  • Next by Date: Re: Copy managed object between contexts?
  • Previous by thread: Re: Copy managed object between contexts?
  • Next by thread: Re: Copy managed object between contexts?
  • Index(es):
    • Date
    • Thread