IPhone : Reading data from NSUserDefaults

on Sunday, February 22, 2015

I write game on Swift in SpriteKit. I have two classes one is named "GameScene" and "PlyScene". I want to read highscore from "PlyScene" in "GameScene" class, but when I do it I have Thread 1:EXC_BREAKPOINT


Cod in PlyScene:



func save() -> Int{

if score2 < score{
score2 = score
println(score2)
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setObject(score2, forKey: "score2")
defaults.synchronize()

}
return 0
}


Code in GameScene:



let defaults = NSUserDefaults.standardUserDefaults()
if let score: AnyObject = defaults.valueForKey("score2"){
println("yes")
scoreText1.text = String(score as NSString)

0 comments:

Post a Comment