NSUserDefaults类registerDefaults的使用



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    NSDictionary *dicDefault = [NSDictionary dictionaryWithObjectsAndKeys: @"hslinux", @"Name",nil];
    [[NSUserDefaults standardUserDefaults] registerDefaults:dicDefault];
    
    return YES;
}


    NSString *strName = [[NSUserDefaults standardUserDefaults] stringForKey:@"Name"];
    NSLog(@" Name = [%@]", strName);
    [[NSUserDefaults standardUserDefaults] setObject:@"?????" forKey:@"Name"];
    
    strName = [[NSUserDefaults standardUserDefaults] stringForKey:@"Name"];
    NSLog(@" Name = [%@]", strName);
    
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"Name"];
    
    NSString *strDefault = [[NSUserDefaults standardUserDefaults] stringForKey:@"Name"];
    NSLog(@"Default Name = [%@]", strDefault);


你可能感兴趣的:(NSUserDefaults)