Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android
by Jakob Iversen, Michael Eierman
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 ...
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