小编Dan*_*iaz的帖子

Swift - NSURL错误

尝试使用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)

nsurl ios swift

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

ios ×1

nsurl ×1

swift ×1