what is the best way for saving username and High Score

前端 未结 2 897
甜味超标
甜味超标 2021-01-15 17:26

In my app I need to save a double value (high score) and String (player name) what should i use to get this.

any idea will be great.

Thank you

2条回答
  •  被撕碎了的回忆
    2021-01-15 18:04

    If this is all you're saving then NSUserDefaults should be fine

    // To store
    [[NSUserDefaults standardUserDefaults] setObject:name forKey:@"name"];
    [[NSUserDefaults standardUserDefaults] setDouble:score forKey:@"score"];
    
    // To read back in
    NSString *name = [[NSUserDefaults standardUserDefualts] objectForKey:@"name"];
    double score = [[NSUserDefaults standardUserDefaults] doubleForKey:@"score"];
    // Don't forget that your name is autoreleased - if you want to keep it, set it to a retained
    // property or retain it yourself :)
    

提交回复
热议问题