How do you encode and decode a CGPoint
struct using NSCoder
?
To encode:
CGPoint point = /* point from somewhere */
NSValue *pointValue = [NSValue value:&point withObjCType:@encode(CGPoint)];
[coder encodeObject:pointValue forKey:@"point"];
To decode:
NSValue *decodedValue = [decoder decodeObjectForKey:@"point"];
CGPoint point;
[decodedValue getValue:&point];
Just an update for iOS developers. You can do the following in Cocoa Touch (but not in Cocoa):
[coder encodeCGPoint:myPoint forKey:@"myPoint"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With