• 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: Creating temporary NSManagedObjects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating temporary NSManagedObjects


  • Subject: Re: Creating temporary NSManagedObjects
  • From: Joanna Carter <email@hidden>
  • Date: Mon, 26 Apr 2010 12:00:28 +0100

Hi Vincent

> Yes. That NSObject holds some properties associated with a graphical layer. I have a lot of them, that I classically save in order to be able to restore the state of the application at launch. Now, to highlight a specific item on a given layer, I create a temporary layer, that I destroy once the user has identified the highlighted item. To keep the drawing code orthogonal, I have to create that temporary NSObject I mentioned, which is needed by my drawInContext: method.

In that case, try this:

Create a category on NSManagedObject -

@interface NSManagedObject (ObjectAsDictionary)

- (NSDictionary *) objectAsDictionary;

@end

@implementation NSManagedObject (ObjectAsDictionary)

- (NSDictionary *) objectAsDictionary
{
  NSDictionary *dictionary = [NSMutableDictionary dictionary];

  NSEntityDescription* entityDescription = [self entity] ;

  for (NSPropertyDescription *propertyDescription in entityDescription)
  {
    id propertyValue = [self valueForKey:[propertyDescription name]];

    [dictionary setValue:propertyValue forKey:[propertyDescription name]];
  }

  return dictionary;
}

@end

Then simply call the following code on the original managed object when :

{
  // assume an NSDictionary *editingWord property declared in your controller class

  editingValues = [editingWord objectAsDictionary];

  // set object controller content to be editingValues

  ...
}

... then after the edits have been made, use the following code to update the object to be stored:

{
  //assume your object to be stored is called originalObject

  [originalObject setValuesForKeysWithDictionary:self.editingValues];

  ...
}

> I hope it is a bit clearer, despite my rusty English.


I speak French if that helps? :-)

Joanna

--
Joanna Carter
Carter Consulting

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Creating temporary NSManagedObjects (From: vincent habchi <email@hidden>)
 >Re: Creating temporary NSManagedObjects (From: Joanna Carter <email@hidden>)
 >Re: Creating temporary NSManagedObjects (From: vincent habchi <email@hidden>)

  • Prev by Date: Re: Creating temporary NSManagedObjects
  • Next by Date: CoreData validation question
  • Previous by thread: Re: Creating temporary NSManagedObjects
  • Next by thread: Re: Creating temporary NSManagedObjects
  • Index(es):
    • Date
    • Thread