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

Ian Rushton
Ian Rushton
15,789 Points

App 'saved point'... Is this achieved through the use of databases?

If I want to increment a value as an anchor for questions in a quiz style app, how do I stop it from resetting to the initial value once somebody closes and reopens the app?

Is there some way of holding this incremented value at its new value or is this only achievable through the use of some kind of database?

Any guidance here would be greatly appreciated!

3 Answers

Jake Adams
Jake Adams
1,608 Points

A simple solution would be to save the current value to NSUserDefaults. This is only local and won't persist if the user reinstalls the app.

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/

Nathan Tallack
Nathan Tallack
22,159 Points

Oh yeah. Did not think of that. Well done. :)

Nathan Tallack
Nathan Tallack
22,159 Points

Core Data is what you are looking for. There is perhaps a course here on TT for it? If not, easy enough to research elsewhere.

Game Centre is what you are looking for to use leaderboards and such like across devices and users. ;)

Ian Rushton
Ian Rushton
15,789 Points

Thanks guys. I will use the NSUserDefaults method for now, but would definitely benefit from learning more about core data! :)