ios - How do I store the High Score? -
this question has answer here:
how store high score. when exit out of app high score goes 0. code determine high score.
if(scoring.text > best.text){ best.text = string(score) }
use nsuserdefaults. see code below...
save score
var defaults: nsuserdefaults = nsuserdefaults.standarduserdefaults() defaults.setobject(self.scorelabel.text, forkey: "score") defaults.synchronize()
load score back
var defaults: nsuserdefaults = nsuserdefaults.standarduserdefaults() if let scoreisnotnill = defaults.objectforkey("score") as? string { self.scorelabel.text = defaults.objectforkey("score") string }
Comments
Post a Comment