无法调用非函数类型UITextField的值

时间:2017-04-13 16:01:27

标签: ios swift

我将我的项目转换为Swift 3并出现错误:无法调用非函数类型的值UITextField

在以下行中:

let url:URL = URL(string: _url!)!

完整代码

func StartDownloadingPL(_ urlFromTextField: String?) -> Void {
    let _url = urlFromTextField
    // some url checks...

    UIApplication.shared.isNetworkActivityIndicatorVisible = true

    let url:URL = URL(string: _url!)!
    let session = URLSession.shared

    var request = URLRequest(url: url)
    request.httpMethod = "GET"
    request.cachePolicy = NSURLRequest.CachePolicy.reloadIgnoringCacheData

    let task = session.dataTask(with: request, completionHandler: {
        (
        data, response, error) in

        DispatchQueue.main.async {
            UIApplication.shared.isNetworkActivityIndicatorVisible = false
        }

        guard let _:Data = data, let _:URLResponse = response, error == nil else {
            print("download error")
            return
        }

        let dataString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
        self.ParsePlaylist(dataString)

    }) 

    task.resume()
}

我从UITextField获取的网址:

@IBAction func DownloadAndParsePL1(_ sender: AnyObject) {
    StartDownloadingPL(Playlist1URL.text)
}

@IBOutlet weak var Playlist1URL: UITextField!

1 个答案:

答案 0 :(得分:1)

我发现一个问题,在将NSURL转换为URL后,它与名为URL的插座有冲突。