Ios userDefaultes本地存储

-(NSString*)readNSUserDefaults:(NSString*)string

{

    NSUserDefaults *userDefaultes = [NSUserDefaults standardUserDefaults];

    

    //读取字典类型NSDictionary类型的数据

    AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];

    

     myDelegate.Dic= [userDefaultes dictionaryForKey:@"MutableDict"];

    

    if(!(myDelegate.Dic))

    {

        myDelegate.Dic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"radio_buy",@"groupId0",@"radio_buy", @"groupId1",@"radio_buy",@"groupId2",@"radio_buy",@"groupId3",@"radio_buy",@"groupId4",@"radio_buy",@"groupId5",@"radio_buy", @"groupId6",@"radio_buy",@"groupId7", nil];

    }

    NSString *myString =  [myDelegate.Dic objectForKey:string];

    return myString;

}

-(void)saveNSUserDefaults:(NSMutableDictionary *)Dictionary

{

    //将上述数据全部存储到NSUserDefaults

    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

    //存储时,除NSNumber类型使用对应的类型外,其他的都是使用setObject:forKey:

    [userDefaults setObject:Dictionary forKey:@"MutableDict"];

    //这里建议同步存储到磁盘中,但是不是必须的

    [userDefaults synchronize];

}


 NSString* StrCheck = [self readNSUserDefaults:string];


 [self saveNSUserDefaults:myDelegate.Dic];



你可能感兴趣的:(Ios userDefaultes本地存储)