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 RTAppDelegate.h.

Listing 20-13: Updating the RTAppDelegate Interface

#import <UIKit/UIKit.h>

@class Trip;

@interface AppDelegate : UIResponder

<UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (nonatomic, strong) Trip *trip;

@property (nonatomic, strong) NSString *

destinationPreference;

- (void) createDestinationModel:(int)destinationIndex;

@end

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 RTAppDelegate.m.

Listing 20-14: Updating the RTAppDelegate ...

Get iPad Application Development For Dummies, 3rd 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.