O'Reilly logo

Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android by Michael Eierman, Jakob Iversen

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

Global Constants

The code you wrote previously uses literal string values to identify the key fields used in NSUserDefaults. This can be a problem, because if they aren’t spelled the same everywhere you use them, you will get some very strange error messages. One solution to this problem is to create an object to hold global constants, and then define the string keys in that object. Here’s how to update the code to be more robust.

1. Select File > New > File, and select Objective-C class in the Cocoa Touch category. Click Next.

2. Name the class Constants and enter NSObject for Subclass Of. Click Next and make sure to save the file inside the project folder, and that the Target for MyContactList CoreData is checked.

3. Open the Constants.h file ...

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