Read and Write User Preferences


/ Published in: Objective C
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. //
  2. // SetPrefsAppDelegate.h
  3. //
  4. #import <UIKit/UIKit.h>
  5.  
  6. @interface SetPrefsAppDelegate : NSObject <UIApplicationDelegate>
  7. {
  8. BOOL saveUsername;
  9. NSInteger preferredIndexInTabbar;
  10. UIWindow *window;
  11. }
  12.  
  13. @property (nonatomic, retain) IBOutlet UIWindow *window;
  14.  
  15. @end
  16.  
  17.  
  18. // SetPrefsAppDelegate.m
  19. //
  20. #import "SetPrefsAppDelegate.h"
  21. #import "Preferences.h"
  22.  
  23. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. // App Delegate implementation
  25. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  26. @implementation SetPrefsAppDelegate
  27.  
  28. @synthesize window;
  29.  
  30. /*------------------------------------------------------
  31. * Read preferences from system
  32. *-----------------------------------------------------*/
  33. -(void) loadPreferences
  34. {
  35. saveUsername = [Preferences shouldSaveUsername];
  36. preferredIndexInTabbar = [Preferences startupTab];
  37. }
  38.  
  39. /*------------------------------------------------------
  40. * Application startup code
  41. *-----------------------------------------------------*/
  42. - (void)applicationDidFinishLaunching:(UIApplication *)application
  43. {
  44. // Load user preferences (notice the default values the first time through)
  45. [self loadPreferences];
  46.  
  47. // Show the current values of the preferences
  48. NSLog(@"Save user preferences: %s", saveUsername == YES ? "Yes" : "No");
  49. NSLog(@"Preferred startup tab: %d", preferredIndexInTabbar);
  50.  
  51. // This is a little contrived, but you get the point...
  52. BOOL saveUname = YES;
  53. NSInteger index = 3;
  54.  
  55. // Write new values to the sytem
  56. [Preferences setPreferences:saveUname startupTab:index];
  57.  
  58. // NSLog(@"Home: %s", NSHomeDirectory());
  59. // NSLog(@"Home: %@", NSHomeDirectory());
  60.  
  61. // Override point for customization after application launch
  62. [window makeKeyAndVisible];
  63. }
  64.  
  65. - (void)dealloc
  66. {
  67. [window release];
  68. [super dealloc];
  69. }
  70.  
  71. @end

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.