O'Reilly logo

Programming in Objective-C, Sixth Edition by Stephen G. Kochan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, 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:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required