Entered the parameter in front of the class:

let defaults = NSUserDefaults.standardUserDefaults() , after it there is a button that makes a comparison, and in it there is a picture + animation and text input:

 if TextField1.text == navigationItem.title { self.StarTextField.hidden = false UIView.animateWithDuration(4.0, animations: { self.StarTextField.frame = CGRect(x: 142, y: -800, width: 316, height: 158)} defaults.setObject(StarTextField, forKey: "StarTextFieldData") return stopFlashingbutton(stopListening()) } else { print("inCorrect TextField") } 

sort of like should save the picture in memory. Further ViewDidLoad () I write:

 defaults.objectForKey("StarTextFieldData") 

Run, crash ... what to do?)

Ps is the Spark CollectionViewController along with the ViewController (the button is in the VC).

    1 answer 1

    NSUserDefaults cannot by default store pictures. Only such types are supported: float, double, int, Boolean, NSURL, NSData, NSString, NSNumber, NSDate, NSArray, NSDictionary. I would save the image to a file, but you can also transfer it to NSData and then save it in the user settings.

    • Thanks, I will transfer it to NSData. And what does it mean (I would save the image to a file) through a binary view? - Alex Gr
    • Yes, in the file. If the picture is one, you can always store it with the same name. If you have a bunch of similar ones, then you can store a dictionary with file names in defaults, or even have a folder with all the program files - make a choice based on the features and growth prospects of your program. - AivanF.