NSUserDefaults not saving

前端 未结 4 1449
迷失自我
迷失自我 2021-01-12 23:14

I am having a problem in my sprite kit app where my NSUserDefaults variable is not working. In createSceneContents (which I know is being called)

4条回答
  •  无人共我
    2021-01-13 00:07

    To store:

    NSString * str = @"name123";
    NSUserDefaults *def=[NSUserDefaults standardUserDefaults];
    [def setObject:str forKey:@"Key"];
    [def synchronize];
    NSLog(@"str = = %@",str);
    

    To Retrieve:

    NSUserDefaults *def=[NSUserDefaults standardUserDefaults];
    NSString *str2 = [def valueForKey:@"Key"];
    NSLog(@" Saved str  = = %@",str2);
    

提交回复
热议问题