/ Published in: Objective C
This is really cool, thanks to the author for putting it together.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// // SetPrefsAppDelegate.h // #import <UIKit/UIKit.h> { BOOL saveUsername; NSInteger preferredIndexInTabbar; UIWindow *window; } @property (nonatomic, retain) IBOutlet UIWindow *window; @end // SetPrefsAppDelegate.m // #import "SetPrefsAppDelegate.h" #import "Preferences.h" //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // App Delegate implementation //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @implementation SetPrefsAppDelegate @synthesize window; /*------------------------------------------------------ * Read preferences from system *-----------------------------------------------------*/ -(void) loadPreferences { saveUsername = [Preferences shouldSaveUsername]; preferredIndexInTabbar = [Preferences startupTab]; } /*------------------------------------------------------ * Application startup code *-----------------------------------------------------*/ - (void)applicationDidFinishLaunching:(UIApplication *)application { // Load user preferences (notice the default values the first time through) [self loadPreferences]; // Show the current values of the preferences NSLog(@"Save user preferences: %s", saveUsername == YES ? "Yes" : "No"); NSLog(@"Preferred startup tab: %d", preferredIndexInTabbar); // This is a little contrived, but you get the point... BOOL saveUname = YES; NSInteger index = 3; // Write new values to the sytem [Preferences setPreferences:saveUname startupTab:index]; // NSLog(@"Home: %s", NSHomeDirectory()); // NSLog(@"Home: %@", NSHomeDirectory()); // Override point for customization after application launch [window makeKeyAndVisible]; } - (void)dealloc { [window release]; [super dealloc]; } @end
URL: http://iphonedevelopertips.com/cocoa/read-and-write-user-preferences.html