I have this game where the user collects coins and I want them to be able to save them and use the coins for in app purchaces. How would I do this? Could I use NSUserDefaults fo
yes, you have different options to save data : nsuserdefaults, write to a file and store the file, coredata, or use a webserver with a database.
If someone knows how to hack your app, he will use what is inside your app (the 3 first methods), this is why many big games use internet (webserver) to check against what was bought by the user.
But, it is not so often that someone hack your game, if he does though, he would never pay anyway. So stay with nsuserdefaults, it is simple and good enough in my opinion.
Reseting the coinScore
NSUserDefaults.standardUserDefaults().removeObjectForKey("coinScore")
loading the saved score
var coinScore = NSUserDefaults.standardUserDefaults().integerForKey("coinScore")
var coins = 5
updating the coinScore
if coins > coinScore {
coinScore = coins
NSUserDefaults().setInteger(coinScore, forKey: "coinScore")
}
println( NSUserDefaults().integerForKey("coinScore").description )
coins += 20
if coins > coinScore {
coinScore = coins
NSUserDefaults().setInteger(coinScore, forKey: "coinScore")
}
println( NSUserDefaults().integerForKey("coinScore").description )