【IPHONE开发-OBJECTC入门学习】NSUserDefaults使用
ELYTAppDelegate.m
#import "ELYTAppDelegate.h" @implementation ELYTAppDelegate @synthesize window = _window; - (void)dealloc { [_window release]; [super dealloc]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; //保存数据 //NSUserDefaults* userDef = [NSUserDefaults standardUserDefaults]; //[userDef setObject:@"NSUserDefaults测试" forKey:@"test"]; //[userDef setInteger:112 forKey:@"number"]; //读取数据 NSUserDefaults* userDef = [NSUserDefaults standardUserDefaults]; NSString* name = [userDef objectForKey:@"test"]; NSInteger number = [userDef integerForKey:@"number"]; NSLog(@"name = %@",name); NSLog(@"number = %d",number); return YES; }
ELYTAppDelegate.h
#import <UIKit/UIKit.h> @interface ELYTAppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end