ios - How do I store the High Score? -


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

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -