Storing NSManagedObject in a dictionary (NSDictionary)

I have a custom class, which is a subclass of NSManagedObject. I would like to store it in a dictionary, but when trying to do so I receive a Property list invalid for format: 200 error.

Here is how I try to create the dictionary:

NSDictionary *dictionary = 
    [NSDictionary dictionaryWithObject: voiceMemo forKey:@"voiceMemo"];

Same result when trying

NSDictionary *dictionary = 
    [NSDictionary dictionaryWithObject: (NSData *) voiceMemo forKey:@"voiceMemo"];

It works, however, when trying to save the individual attributes separately:

NSDictionary *dictionary = 
    [NSDictionary dictionaryWithObject: voiceMemo.attribute forKey:@"attribute"];

NSDictionary should be able to store data objects, so I'm guessing, the real question is how to cast an NSManagedObject object to NSData

18
задан antalkerekes 14 April 2011 в 14:02
поделиться