Disclaimer: I have modified/am modifying a project my tutor downloaded off the internet.
This is my homework project: 3 fortune cookies on the screen, user hits "Find out my fortune" button, which selects one of the three cookies at random (using the .randomElement()
property). A window opens, displaying that random cookie image. However, I am unable to set the image within the window to the result of the .randomElement()
property
I have already tried trying to convert the UIImage to UIImageView and vice versa, but now am at my wits end.
Here is the global class of the random element being formed
class globalElements {
static let cookiesArray = [globalElements.numberOne,
globalElements.numberTwo, globalElements.numberThree]
static let randomlyAssignedCookie = cookiesArray.randomElement()
}
//And here is where the title error shows up:
let randomlyChosenFortune: UIImageView = {
let image = UIImageView()
image.translatesAutoresizingMaskIntoConstraints = false
image.clipsToBounds = true
image.contentMode = .scaleAspectFit
image.image = globalElements.randomlyAssignedCookie //(error: Cannot assign value of type 'UIImageView?' to type 'UIImage?')//
return image
}()