The code is:
@IBAction func CheckBoxTuesdayButtonPressed(_ sender: Any) {
if CheckBoxTuesday.image == UIImage(imageLiteralResourceName: "CheckmarkButtonPressed"){
CheckBoxTuesday.image = UIImage(imageLiteralResourceName: "CheckBoxButton")
}
else{
CheckBoxTuesday.image = UIImage(imageLiteralResourceName: "CheckmarkButtonPressed")
UserDefaults.standard.setValue(CIImage.self, forKey: "TuesdayChecked")
}
I tried the Userdefault line of code but it said i couldnt convert it to NSuserdefault.
What you are trying to do is not recommended. You are only supposed to save small snippets like user preferences.
If you are determined to do it anyway, you need to convert your data to one of the small number of "property list types" that UserDefaults supports.
They are, using their Objective-C names (With the Swift name in parens)
NSData (Data), NSString (String), NSNumber (Still NSNumber), NSDate (Date), NSArray (Array), NSDictionary (Dictionary)
(NSNumber is an object wrapper for a scalar value. UserDefaults has helper functions that let you read/write scalar values like Int, Float, and Double.)
In your case you'd have to convert your image to
Dataand the save theData. (But don't do that.)Edit:
Also note that there are various problems with your code. The line that attempts to save the image tries to save
CIImage.selfwhich is totally wrong.In your case it looks like you are trying to save the state of a user's checkbox selection. Saving an image to remember a user's selection is silly. Create an enum with an Int raw value and save the rawValue to UserDefaults.
And your code that figures out what to save makes no sense either. That code is riddled with errors.