【问题标题】:Swift Error: cannot invoke `dataWithRequest` with an argument list of type `(NSURL, completionHandler:(_,_,_) -> VoidSwift 错误:无法使用类型为 `(NSURL, completionHandler:(_,_,_) -> Void 的参数列表调用 `dataWithRequest`
【发布时间】:2015-11-24 13:48:21
【问题描述】:
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()
        }
    }

    ....
}

我收到错误消息:“无法使用类型为 `(NSURL,completionHandler:(,,_) -> Void 的参数列表调用 dataWithRequest

我能做什么???

【问题讨论】:

    标签: ios swift nsurl nsurlsession


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多