Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serialize CGAffineTransform to store in NSUserDefaults

Tags:

ios

How would I store a CGAffineTransform in NSUserDefaults? Since it contains 6 float values it takes a lot of repetitive work to store each value as float... so I'm wondering if there is a smarter way.

like image 675
Jonny Avatar asked Dec 17 '10 10:12

Jonny


2 Answers

Use NSStringFromCGAffineTransform() and CGAffineTransformFromString().

Using NSValue, I got:

-[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value 'CGAffineTransform: {{0.9291659, 0, 0, -0.9291659}, {41.675232, 823.75122}}' of class 'NSConcreteValue'. Note that dictionaries and arrays in property lists must also contain only property values.

like image 86
invalidname Avatar answered Sep 28 '22 19:09

invalidname


Wrap it in an NSValue instance:

NSValue *affineTransformValue = [NSValue valueWithCGAffineTransform:myTransform];
like image 34
Ole Begemann Avatar answered Sep 28 '22 21:09

Ole Begemann