Writing Encoding and Decoding Methods

Basic Objective-C class objects such as NSString, NSArray, NSDictionary, NSSet, NSDate, NSNumber, and NSData can be archived and restored in the manner just described. That includes nested objects as well, such as an array containing a string or even other array objects.

This implies that you can’t directly archive your AddressBook that we developed in Chapter 15, “Numbers, Strings, and Collections,” using this technique because the Objective-C system doesn’t know how to archive an AddressBook object. If you try to archive it by inserting a line such as

[NSKeyedArchiver archiveRootObject: myAddressBook toFile:  @"addrbook.arch"];

into your program, you get the following message if you run the program:

Get Programming in Objective-C, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.