Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSArchiver vs. NSKeyedArchiver

How do you know if you need to use NSArchiver or NSKeyedArchiver? What's the difference?

like image 351
node ninja Avatar asked Sep 19 '10 08:09

node ninja


1 Answers

NSArchiver supports the key-less coding methods like –encodeObject: or –decodePoint, while NSKeyedArchiver supports the key-based coding methods like –encodeObject:forKey: or –decodePointForKey:. The major difference is that on archivers, you need to decode stuff in exactly the same way as you encoded it. Every key can be decoded exactly once. Keyed archivers, on the other hand, do not restrict you to any order and you can freely decode the same object multiple times.

Whenever possible, use NSKeyedArchiver. It's newer and will probably eventually replace the non-key-based variant.

like image 183
Max Seelemann Avatar answered Sep 19 '22 13:09

Max Seelemann