HeeysamH HeeysamH - 1 year ago 72
Swift Question

Swift Spritekit NSUserdefaults between 2 swift scenes/files

How do i share NSUserdefaults objects between 2 scenes/files

so if i create 1 in hello.swift

i will be able to load it in dad.swift?

i tried to do it the normal way but it didn't seem to work

Thanks for your help and time!

Answer Source

NSUserDefaults is shared throughout the application. If you put this in one file:

NSUserDefaults.standardUserDefaults().setObject(myObject, forKey: "key")

Then you can retrieve it in another file:

var myObject = NSUserDefaults.standardUserDefaults().objectForKey("key")