Return to Snippet

Revision: 24584
at March 4, 2010 10:42 by espinallab


Initial Code
//
//  SetPrefsAppDelegate.h
//
#import <UIKit/UIKit.h>
 
@interface SetPrefsAppDelegate : NSObject <UIApplicationDelegate> 
{
  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

Initial URL
http://iphonedevelopertips.com/cocoa/read-and-write-user-preferences.html

Initial Description
This is really cool, thanks to the author for putting it together.

Initial Title
Read and Write User Preferences

Initial Tags
user

Initial Language
Objective C