Question

I'm looking to have a system where it updates the score the user has if they get the answer right in a multiple choice question. I have an IBAction that runs when the user selects the right choice and I want it to update the score. i.e. score + 2 when answer is correct Is it something with CGFloat or NSInteger?

Was it helpful?

Solution

Try something like this:

//.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;

Wherever you want to update the score, just call the scoreChanged method. Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top