Cocoa Programming for OS X: The Big Nerd Ranch Guide
by Aaron Hillegass, Adam Preble, Nate Chandler
For the More Curious: Preventing Infinite Loops
The astute reader may be wondering, “If object A causes object B to be encoded, and object B causes object C to be encoded, and then object C causes object A to be encoded again, couldn’t it just go around and around in an infinite loop?” It would, but NSKeyedArchiver was designed with this possibility in mind.
When an object is encoded, a unique token is also put onto the stream. Once archived, the object is added to the table of encoded objects under that token. When told to encode the same object again NSKeyedArchiver simply puts a token in the stream.
When it decodes an object from the stream NSKeyedUnarchiver puts both the object and its token in a table. If it finds a token with ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access