I am creating horses in a horse simulator by appending an array with:
But the basePhenotype property is set to be a UIImage. Even though bayArray is only images, it won't accept this array as an input. How can I write it differently?
Code Block Horses.append(Horse( //Genotype (two letters) ext: ["E", "e"][Int.random(in:0...1)]+["E", "e"][Int.random(in:0...1)], //Phenotype (an image) basePhenotype: [bayArray.randomElement()],
But the basePhenotype property is set to be a UIImage. Even though bayArray is only images, it won't accept this array as an input. How can I write it differently?
I don't understand how your create tobianoArray.
But this should work:
But this should work:
Code Block let img1 = UIImage(imageLiteralResourceName: "Tobiano1") let img2 = UIImage(imageLiteralResourceName: "Tobiano2") let img3 = UIImage(imageLiteralResourceName: "Tobiano3") let tobianoArray = [img1, img2, img3] let pheno = tobianoArray.randomElement() // Take care, that's an optional // You could use ?? : // let pheno = tobianoArray.randomElement() ?? UIImage(imageLiteralResourceName: "defaultImage")