系统相关
首页 > 系统相关> > linux – IBM Swift Sandbox:运行NSURLSession:运行代码时出错:未知错误代码132

linux – IBM Swift Sandbox:运行NSURLSession:运行代码时出错:未知错误代码132

作者:互联网

我正在尝试执行以下脚本:

import Foundation

class TestURLSession{

var session: NSURLSession!

func run(){
    session = NSURLSession.sharedSession()

    let url = NSURL(string: "http://www.veenex.de/tmp/json")
    let request = NSMutableURLRequest(URL: url!)
    request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
    request.HTTPMethod = "GET"

    let getDataTask = session.dataTaskWithRequest(request, completionHandler: {(data, response, error) in

        // HTTP Response contains an error
        if let httpResponse = response as? NSHTTPURLResponse {
            if httpResponse.statusCode != 200 {
                print("response was not 200: \(response)")
                return
            }
        }

        // Error submitting Request
        if error != nil {
            print("error submitting request: \(error)")
            return
        }

        // print data
        if data != nil{

            do {
                let json = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! NSArray

                for entry in json {
                    print(entry)
                }

            } catch {
                print("Error printing data")
            }

        }


    });

    getDataTask.resume()
}

}

let testURLSession = TestURLSession()
testURLSession.run()

但是我收到错误消息:“运行代码时出错:未知错误代码132”.
在Xcode Playground中执行代码它可以工作.

解决方法:

尚未编写NSURLSession的纯Swift实现.查看Apple的GitHub repo for Foundation上的NSURLSession.swift文件.

每个方法都是NSUnimplemented(),这意味着它尚未实现.在此类完成之前,它将无法在Linux和IBM的Swift Sandbox上使用.

标签:linux,swift,nsurlsession,ibm-swift-sandbox
来源: https://codeday.me/bug/20190611/1220646.html