Reputation: 656
I've found the solution but it is not in Swift: Converting UIImageView to UIImage
I've even went rogue by trying to implement it in Swift by using UnsafeMutablePointed and had no luck.
However, pointers are typically frowned upon in Swift and it would be nice if there was a simple one-liner solution to this!
Example Code:
let test1:UIImageView = UIImageView(image: UIImage(named: "test"))
let test2 = test1.image // This fails with an error: Instance member ‘test1’ cannot be used on type ‘viewController’
Upvotes: 3
Views: 8143
Reputation: 13316
The UIImageView
has a property called image
which stores its UIImage
. So to retrieve an UIImageView
's image, all you need to do is access the property:
let myImage = imageView.image
That's really all there is to it.
Upvotes: 3
Reputation: 9391
I highly advise you to learn about Objective-C, as that will help you greatly in finding out how to do things in iOS (Cocoa-Touch).
The solution is identical to Objective-C:
imageView.image
Upvotes: 8