在Swift中显示URL中的图像

时间:2016-03-29 03:45:42

标签: swift uiimage

fatal error: unexpectedly found nil while unwrapping an Optional value

我有上述错误,我正试图破解解决方案。

@IBOutlet var imageView: UIImageView?

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    let url = NSURL(fileURLWithPath: "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c2/Faust_bei_der_Arbeit.JPG/220px-Faust_bei_der_Arbeit.JPG");
    let imageData: NSData? = NSData(contentsOfURL: url)
    let image = UIImage(data: imageData!)
    imageView?.image = image
}

0 个答案:

没有答案