我从webserice带来了图片网址.我将它从下面的代码转换为图像.
打开时我收到错误..
let url = NSURL(string: contactResult.conImageUrl)
let data = NSData(contentsOfURL: url!)
var imageUrl: UIImage = UIImage()
println("URL \(url)")
println("data \(data)")
imageUrl = UIImage(data: data!)! // here i am getting the error (unexpectedly found nil while unwrapping an Optional value)
Run Code Online (Sandbox Code Playgroud)
这里是我的图片网址:http:// <...> /peoplefinder/imgs_styles/silhouette.jpg
有人可以尽快帮助我吗?
您可以安全地打开图像,如下所示:
if let image = UIImage(data: data) {
image // you can use your image UIImage (note: image it is not an optional here)
}
Run Code Online (Sandbox Code Playgroud)