1

This may be me being incredibly thick, but how do I store a BOOL in a UIDocument? I am currently using NSFileWrappers for storing a string and an image in the "contentsForType:error:" method, but seeing as there's no way to convert a bool into NSData, what would be the best way?

Thanks

cacau
  • 3,606
  • 3
  • 21
  • 42
Carl Goldsmith
  • 750
  • 1
  • 5
  • 11

1 Answers1

1

You can get a NSData object from a BOOL:

NSData* data=[NSKeyedArchiver archivedDataWithRootObject: [NSNumber numberWithBool: YES]];
Ramy Al Zuhouri
  • 21,580
  • 26
  • 105
  • 187
  • If I were to save it in a dictionary, what implications would that have for extracting the data in the "loadFromContents:ofType:error" method? – Carl Goldsmith Sep 15 '12 at 22:20
  • You put all the object that you need to encode (without converting them into NSData) in the dictionary, and encode the whole dictionary.Then in the loadFromContents method with NSKeyedUnarchiver's unarchiveObjectWithData method you get the original dictionary. – Ramy Al Zuhouri Sep 15 '12 at 22:50