Post

Replies

Boosts

Views

Activity

Fill an array with String variable
Hello everyone ! I don't understand, I write this code to fill the array with the string variable value but there are error.. Below my code :     var Empty_image = ""     var Abductor_machine_image = "Abductor machine"     var Abs_crunch_machine_image = "Abs crunch machine"     var Abs_crunch_oblique_image = "Abs crunch oblique"     var Abs_floor_oblique_image = "Abs floor oblique"     var Abs_incline_bench_image = "Abs incline bench"     var Abs_machine_image = "Abs machine"     var Abs_roman_chair_oblique_image = "Abs roman chair oblique"     var Abs_rotation_crunch_image = "Abs rotation crunch"      let Images3 = [Empty_image, Abductor_machine_image, Abs_crunch_machine_image, Abs_crunch_oblique_image, Abs_floor_oblique_image, Abs_incline_bench_image, Abs_machine_image, Abs_roman_chair_oblique_image, Abs_rotation_crunch_image] And I have this error for each variable but I don't be able to fix it : "Cannot use instance member 'Abductor_machine_image' within property initializer; property initializers run before 'self' is available" Sorry I beginning on swift..
2
0
373
Sep ’22
UIImage (named : ""\(UserDefaults.standard.string(forKey: "value") ?? "")") doesn't match
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...
4
0
458
Sep ’22