Swift Error: cannot invoke `dataWithRequest` with an argument list of type `(NSURL, completionHandler:(_,_,_) -> Void

Swift Error: cannot invoke `dataWithRequest` with an argument list of type `(NSURL, completionHandler:(_,_,_) -> Void

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var textfield: UITextField!

    @IBAction func whatIsThePrice(sender: AnyObject) {
        var url = NSURL(string: "https://uk.finance.yahoo.com/q?s=" + textfield.text + "&ql=1")

        if url != nil {
            // ##### I GET THE ERROR HERE #####
            let task = NSURLSession.sharedSession().dataTaskWithRequest(url!, completionHandler: { (data, response, error) -> Void in
                ...
            })

            task.resume()
        }
    }

    ....
}

我收到错误:"cannot invoke dataWithRequest with an argument list of type `(NSURL, completionHandler:(,,_) -> Void"

我能做什么???

您传递的是 NSURL,因此您需要使用 dataTaskWithURLdataTaskWithRequest 需要一个 NSURLRequest

let task = NSURLSession.sharedSession().dataTaskWithURL(url!, ...