Saving NSDictionary to NSUserDefaults

后端 未结 2 505
花落未央
花落未央 2020-12-13 08:50

I have a NSMutableDictionary, and i have added values to it (several key pair values). Now i require to save this NSMutableDictionary to a NSUserDefaults object.

1.

2条回答
  •  遥遥无期
    2020-12-13 09:04

    NSMutableDictionary *profileDictionary = [[NSMutableDictionary  alloc] init];
    [profileDictionary setObject:txt_Username.text forKey:@"USERNAME_KEY"];
    [profileDictionary setObject:txt_Password forKey:@"PASSWORD_KEY"];
    [[NSUserDefaults standardUserDefaults] setObject:profileDictionary forKey:@"PROFILE_KEY"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    

    This is what you expected.

提交回复
热议问题