When to use NSData and when to use <NSCoding>?


#1

After I finished this chapter I’ve got three questions:

  1. When should I use NSData to save objects to a file/files and when should I conform <‘NSCoding’> protocol to save objects to a file/files?

  2. When should I save all objects to one single file and when should I save one file for each object?

  3. [aCoder encodeObject:self.itemName forKey:@“itemName”] here self.itemName is a string object, can I encode objects that are created by me?

Thanks!


#2
  1. The book says NSData is for binary data and NSString is for text data, and to use archiving in the object, you should add NSCoding protocol declaration.

  2. Several small items are saved in one file, while big image data is saved individually as per the example of the book.

  3. Yes, for example, we encoded BNRItem created by us.