lundi 29 décembre 2014

Reference to object doesn't seem to be updating


Vote count:

0




I've now run out of ideas, I must be missing something...


These are my 3 classes:



var tutorial : Tutorial = Tutorial()

class Tutorial {

var swipeToOpenMenu = false

func load() {
println("Loading tutorial settings")
if global.persistantSettings.objectForKey("swipeToOpenMenu") != nil {
swipeToOpenMenu = global.persistantSettings.objectForKey("swipeToOpenMenu") as Bool
}
}

func save() {
global.persistantSettings.setObject(swipeToOpenMenu, forKey: "swipeToOpenMenu")
global.persistantSettings.synchronize()
}

func reset() {
println("Before \(swipeToOpenMenu)")
swipeToOpenMenu = false
println("After \(swipeToOpenMenu)")
save()
}


2nd Class



class TabBarViewController {
...
@IBAction func home(sender: AnyObject) {
println(global.persistantSettings.objectForKey("swipeToOpenMenu") as Bool)
if global.persistantSettings.objectForKey("swipeToOpenMenu") as Bool == false {
viewSwipeRight.hidden = false
animateSwipeRight()
}
}


And in my 3rd class I basically call the reset method from tutorial.swift (1st class)...


Note how the tutorial variable is init'd as a Global at the top of its class.


Some things to note: TabBarViewController is a parent view controller which presents most of the screens in my app within itself. One of those screens is the settings view controller (3rd class). When the 'home' button is tapped, it should open up a different view controller, but should also show the tutorial screen again if that variable is set to False in tutorial.swift (which it would have been as it was just reset - even the println's say before - true, after - false. But the println in the home button prints out true, always (except when the app starts and the variable is init'd as false.)


I have tried calling the variables via tutorial.swipeToOpenMenu, I've tried calling them directly from NSUserDefaults (as seen in my code here), I've tried synchronising right before calling them as well...


Any ideas where to start? Let me know if I must add information... I have trimmed down the code above to whats involved in the pickle i have found myself in...



asked 1 min ago







Reference to object doesn't seem to be updating

Aucun commentaire:

Enregistrer un commentaire