Question

I'd like to encode an NSEvent using NSPropertyListSerialization, but NSPropertyListSerialization only accepts NSData, NSString, NSArray, NSDictionary, NSDate, and NSNumber objects.

Is there a recommended way to convert an NSEvent to a NSPropertyListSerialization-capable NSDictionary (and to restore an NSEvent from such an NSDictionary)?

Was it helpful?

Solution

In this situation you need to handle saving and restoring the object yourself. Or rather, the pieces of the object you're interested in, either by putting each value in an NSDictionary or storing them separately and using the values to create a new object when your class is decoded.

This situation is a little weird since you usually don't create or store NSEvent objects. If you're doing something like storing the last touch coordinate, consider using an CGPoint instead. Not only will you reduce your memory footprint by a small amount, but you can then use an NSValue to serialize the point.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top