I'm trying to save a simple functionality, where a user clicks a button and the image changes, I want the image to stay the same when the user clicks the button. for instance, if the user clicks the button and the imageview is named hello
it changes to an imageview named goodbye
when the app closes and is deleted from the background, when the user reopens the app the goodbye
image will be displayed.
What do I need to do for it to save?
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var button: UIImageView!
@IBAction func addButton(sender: AnyObject) {
button.image = UIImage(named: "testButtonWin")
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
NSUserDefaults.standardUserDefaults().setObject(button, forKey: "button")
NSUserDefaults.standardUserDefaults().synchronize()
//println(NSUserDefaults.standardUserDefaults().objectForKey("button")!)
}
}