Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

how can I Keep a history of scores (iOS simple game)

Hi I'm trying to build a memory card game for iOS and having trouble with saving score history and display it to a table view. can anyone help me with that?

Cheers

2 Answers

The easiest way to save a score in iOS, is to use NSUserDefaults.

let gameScore = 10 

NSUserDefaults.standardUserDefaults().setInteger(gameScore, forKey: "someKey") // Set the value for the key


let getScoreValue = NSUserDefaults.standardUserDefaults().integerForKey("someKey") // Retrieve score with same key

Thanks Gary