尝试使用NSURL下面的类时出错,下面的代码实际上是试图将我从Facebook拉入的图像存储到imageView.错误如下:
value of optional type 'NSURL?' not unwrapped, did you mean to use '!' or '?'
Run Code Online (Sandbox Code Playgroud)
不知道为什么会这样,帮忙!
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var myImage: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
let myProfilePictureURL = NSURL(string: "http://graph.facebook.com/bobdylan/picture")
let imageData = NSData(contentsOfURL: myProfilePictureURL)
self.myImage.image = UIImage(data: imageData)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Run Code Online (Sandbox Code Playgroud)