I'm fairly certain this is not possible exactly like you want it. Image views don't retain the file they loaded the image from, just the image data itself. But I assume you're setting the image names in IB and trying to get that name after a touch event, in that case you could set the image name in the element's restoration ID and retrieve the name via the restorationIdentifier property of the touched element.
You can get the touched element like this:
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch: UITouch = touches.first {
let location = touch.location(in: self.view)
let touchedView = self.view.hitTest(location, with: event)
print(touchedView.restorationIdentifier)
}
}
Note that you have to set the image file name twice if you want to do it like this, and change the value twice when making changes. What you are trying smells of bad design, so if there's another way I'd go with that.