Hi everyone,
I will try to explain my problem and what I already tried
I have a Controller where I chose 2 images with a picker view. For each picker view I save the name of the image (from assets) in a Label. Then, I save the label.text in a like that :
UserDefaults.standard.set(Exo_1_Label.text, forKey: "Nom_Exo_1_Jour_1_Programme_1") UserDefaults.standard.set(Exo_2_Label.text, forKey: "Nom_Exo_2_Jour_1_Programme_1")
For this part is ok because when I use these exercise names in another controller view is working. But, my problem is that when I want to use these names to call the image in UIImageViews it doesn't work.
Image_Exo01.image = UIImage (named: "(UserDefaults.standard.string(forKey: "Nom_Exo_1_Jour_1_Programme_1") ?? "")")
Image_Exo02.image = UIImage (named: "(UserDefaults.standard.string(forKey: "Nom_Exo_2_Jour_1_Programme_1") ?? "")")
For the first image, it work but not for the second.. I don't understand because the value of the second Userdefaults is right because I use it for the title of the controller.. I tried to use the name of the image and it working, so I think the problem is from to use twice the UIImage (named : ...) with userdefaults in same time
Maybe someone knows what is my problem...
This is a bit puzzling:
Image_Exo01.image = UIImage (named: "(UserDefaults.standard.string(forKey: "Nom_Exo_1_Jour_1_Programme_1") ?? "")") // <-- #1
Is that really your code? It looks like you mean:
Image_Exo01.image = UIImage (named: UserDefaults.standard.string(forKey: "Nom_Exo_1_Jour_1_Programme_1") ?? "") // <- #2
or maybe:
Image_Exo01.image = UIImage (named: "\(UserDefaults.standard.string(forKey: "Nom_Exo_1_Jour_1_Programme_1") ?? "")") // <-- #3
There's really no point to #3 in this case, since it's equivalent to #2 but harder to read.