Friday, October 19, 2012

iOS 資料保存 Data Persistence - NSUserDefaults

NSUserDefaults (Setting)
Property List (plist)
CoreData


  1. - (void)applicationDidEnterBackground:(UIApplication *)application
  2. {
  3.     NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
  4.     [userDefault setObject:@"白彼得" forKey:@"name"];
  5.     [userDefault synchronize];
  6. }
  7. - (void)applicationWillEnterForeground:(UIApplication *)application
  8. {
  9.    NSString *name = [[NSUserDefaults standardUserDefaults] objectForKey:@"name"];
  10.    NSLog(@"name %@", name);
  11. }



.

No comments:

Post a Comment