Saving the Destination Choice and Selecting a Destination
At this point, if you were to run your project, you would be able to tap the Destination button, choose a destination, and see the data for either New York or San Francisco.
But you’re not done yet.
First, if the application is terminated (and I mean terminated, not running in the background and relaunched), the user will find that the destination she selected has reverted back to being the default one. You would like RoadTrip to be in position to save, and then restore, the user’s destination preference. (In Chapter 11, you see how to default to the first destination in the
plist. I mention in that chapter that I show you how to allow the user to select a destination in Chapter 20, and here you are.)
Start by adding the
destinationPreference property to
RTAppDelegate by adding the bolded code in Listing 20-13 to
Listing 20-13: Updating the RTAppDelegate Interface
@interface AppDelegate : UIResponder
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, strong) Trip *trip;
@property (nonatomic, strong) NSString *
- (void) createDestinationModel:(int)destinationIndex;
Now create the accessors for this property and the name of the key you’ll use in
NSUserDefaults for the destination preference by adding the bolded code in Listing 20-14 to
Listing 20-14: Updating the RTAppDelegate ...