开发者

Objective-C: How to cast a boolean as an object for use with NSKeyedArchiver

开发者 https://www.devze.com 2022-12-14 19:02 出处:网络
I need to cast a boolean as an object, or NSKeyedArchiver throws a m开发者_开发技巧emory access error. What\'s the best way to do this?How about encodeBool:forKey: instead?Further to NSD\'s answer, in

I need to cast a boolean as an object, or NSKeyedArchiver throws a m开发者_开发技巧emory access error. What's the best way to do this?


How about encodeBool:forKey: instead?


Further to NSD's answer, in a general sense: Cocoa often requires actual objects for various methods. When the type you have is an ordinal type, such as int, BOOL, or float, you can wrap it in an NSNumber. For other types, you may need to wrap it in an NSValue or NSData (which is essentially an arbitrary binary buffer of a given length).

0

精彩评论

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

关注公众号