Ios 记录分数最简单的方法是什么?

Ios 记录分数最简单的方法是什么?,ios,nsinteger,cgfloat,Ios,Nsinteger,Cgfloat,我希望有一个系统,它可以更新用户的分数,如果他们在多项选择题中得到正确的答案。我有一个iAction,当用户选择正确的选项时运行,我希望它更新分数。 i、 e.答案正确时,得+2分 是CGFloat还是NSInteger?试试下面的方法: //.h File @property (nonatomic) NSUInteger score; //If the user can get a negative score, change "NSUInteger" to "NSInteger" -(voi

我希望有一个系统,它可以更新用户的分数,如果他们在多项选择题中得到正确的答案。我有一个iAction,当用户选择正确的选项时运行,我希望它更新分数。 i、 e.答案正确时,得+2分
是CGFloat还是NSInteger?

试试下面的方法:

//.h File
@property (nonatomic) NSUInteger score; //If the user can get a negative score, change "NSUInteger" to "NSInteger"
-(void)scoreChanged;

//.m File
-(void)scoreChanged{
    self.score += 2; //You can change the 2 to any number
}

//viewDidLoad
self.score = 0;
无论您想在哪里更新分数,只需调用scoreChanged方法。希望这有帮助