开发者

Serialize CGAffineTransform to store in NSUserDefaults

开发者 https://www.devze.com 2023-01-30 21:47 出处:网络
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开发者_如何学C\'m wondering if there is

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开发者_如何学C'm wondering if there is a smarter way.


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.


Wrap it in an NSValue instance:

NSValue *affineTransformValue = [NSValue valueWithCGAffineTransform:myTransform];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号