Chetan
Chetan

Reputation: 47981

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

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

Upvotes: 1

Views: 4428

Answers (2)

gavinb
gavinb

Reputation: 20018

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

Upvotes: 4

Azeem.Butt
Azeem.Butt

Reputation: 5861

How about encodeBool:forKey: instead?

Upvotes: 10

Related Questions