1

I need to cast a boolean as an object, or NSKeyedArchiver throws a memory access error. What's the best way to do this?

1
  • Note: I am using the encodeObject: method of NSCoder to encode my boolean.
    – Chetan
    Dec 28, 2009 at 6:27

2 Answers 2

10

How about encodeBool:forKey: instead?

1
  • Ah, I wasn't aware that function was available. Thanks.
    – Chetan
    Dec 28, 2009 at 6:56
4

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.