-2

I am using NSCoding and NSArchiver to persist my iOS App Data. But I want to know if it is equivalent to using zip / unzip software? If not, how does it work?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user8637708
  • 3,303
  • 2
  • 13
  • 15

2 Answers2

2

You can read the docs to get a rough idea of how NSArchiver works:

[...] provides a way to encode objects into an architecture-independent format that can be stored in a file

Basically, it converts an object in memory (and all the other objects that it references, and the objects that those objects references... i.e. "object graph") into a file that can be stored in a file.

This is not the same as compression. NSArchiver simply encodes your objects into some format (binary, XML etc.). Compression would be to make that encoded binary file smaller.

See this post for how to compress files.

Sweeper
  • 213,210
  • 22
  • 193
  • 313
1

In effect, it is a property list. That is why NSKeyedArchiver has an outputFormat property that can be an XML property list or a binary property list.

See the documentation on the PropertyListSerialization class for more about what that means.

You can actually write an archive to disk, open it as XML, and read it.

matt
  • 515,959
  • 87
  • 875
  • 1,141