Swift中URL提取的错误结果

时间:2017-02-11 19:23:08

标签: swift ios10

使用Xcode版本8.2.1(8C1002),为什么我在这里得到let result = "4247577657"?我试图弄清楚我的代码是如何从我的url变量中提取的。

import UIKit
import PlaygroundSupport

PlaygroundPage.current.needsIndefiniteExecution = true

let configuration = URLSessionConfiguration.default
configuration.allowsCellularAccess = true

let session = URLSession(configuration: configuration)

let url = NSURL(string: "http://kvisionphoto.com/4247577657.txt")

let task = session.dataTask(with: url as! URL) {
    (data, response, error) in
    guard let data = data else {print (error ?? "error") ; return}

    let result =  try? String(contentsOf: url as! URL)

    print(result ?? "nil" )

    PlaygroundPage.current.finishExecution()
}

task.resume()

1 个答案:

答案 0 :(得分:1)

4247577657是服务器上的文字......

Here's what I get