Skip navigation.
 
mlRe: archiving a predicate
FROM : Matthew Firlik
DATE : Sun Jun 25 20:32:27 2006

On Jun 25, 2006, at 11:21 AM, John R. Timmer wrote:

> I tried to use an NSValueTransformer to convert an NSPredicate to 
> data, but it doesn't seem to work (the following gets logged: 
> "exception: *** -encodeObject:forKey: only defined for abstract 
> class.  Define -[NSArchiver encodeObject:forKey:]!").  I could break 
> the predicate down into format string and the values to substitute, 
> but it's supposedly NSCoding compliant.  Any advice on how to handle 
> this?


Keyed-archiving will work just fine.  You can see code for this in the 
CoreRecipes example (http://developer.apple.com/samplecode/CoreRecipes/index.html
), in the "SmartGroup" entity.  That entity uses a persistent NSData 
attribute and a transient NSPredicate attribute to approximate 
smartgroup functioanlity.  The encoding methods is as simple as:

   NSData *predicateData = [NSKeyedArchiver 
archivedDataWithRootObject:yourPredicate];

and the decoding is also straightforward:

   NSPredicate *yourPredicate = [NSKeyedUnarchiver 
unarchiveObjectWithData: predicateData];

- matthew

Related mailsAuthorDate
mlarchiving a predicate John R. Timmer Jun 25, 20:21
mlRe: archiving a predicate Matthew Firlik Jun 25, 20:32