I won't get to into the weeds on what my app is ultimately doing but the issue I'm having is when I click on one of 6 button that all have a UIImage in their imageView I then try to reference the image name (the images are coming from my assets) to switch over which button was pressed and use the results to update a label.
The values are being set and printing out in the action, however the switch statement always falls through to default and I can't figure out why. Are the button imageViews effecting the image names?
@IBOutlet var feelingLabel: UILabel!
var feelingImage: UIImage? {
didSet {
switch feelingImage {
case UIImage(named: "happyFace"):
self.feelingLabel.text = "feeling happy"
case UIImage(named: "fineFace"):
self.feelingLabel.text = "feeling fine"
case UIImage(named: "angryFace"):
self.feelingLabel.text = "feeling angry"
case UIImage(named: "anxiousFace"):
self.feelingLabel.text = "feeling anxious"
case UIImage(named: "sadFace"):
self.feelingLabel.text = "feeling sad"
case UIImage(named: "sickFace"):
self.feelingLabel.text = "feeling sick"
default:
self.feelingLabel.text = "feeling..."
}
}
}
// all six buttons are connected to this action
@IBAction func feelingButtonTapped(_ sender: UIButton) {
guard let selectedFeelingImage = sender.imageView?.image,
selectedFeelingImage != self.feelingImage else {
self.feelingImage = nil
return
}
self.feelingImage = selectedFeelingImage
print(selectedFeelingImage)
print(self.feelingImage)
}