Search code examples
iosswiftuiimageviewuiimagejpeg

Cannot display jpeg from outside asset folder in swift 2


This is probably a problem with my ignorance, but I am simply trying to show an image ... as per the code below.

I don't get any errors. The image exists, but does not appear in the simulator. If I change the path string to a non-existing image I get an error, so I assume it is finding the image correctly. What am I missing?

image of view controller

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var hotspotImage: UIImageView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        let path = "/Users/Mel/Library/Developer/CoreSimulator/Devices/5760868E-BC01-4021-9500-1D4C09FE5106/data/Containers/Data/Application/2E99C508-30E5-4C83-BC72-CBF141A64769/Documents/tours/22/HI2.jpg"
        let image = UIImage(contentsOfFile: path)
        hotspotImage = UIImageView(image: image!)
    }

}

Solution

  • instead of hotspotImage = UIImageView(image: image!) try hotspotImage.image = image!.