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
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 )