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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to