IBM Swift 沙箱:运行 NSURLSession:错误运行 代码:未知错误代码 132
IBM Swift Sandbox: Running NSURLSession: Error running code: unknown error code 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()
但我收到错误消息:"Error running code: unknown error code 132."。
在 Xcode Playground 中执行代码可以正常工作。
尚未编写 NSURLSession
的纯 Swift 实现。查看 Apple 的 GitHub 基础库中的 NSURLSession.swift
文件。
每个方法都是NSUnimplemented()
,也就是说,嗯,还没有实现。在 class 完成之前,它将无法在 Linux 和 IBM 的 Swift 沙盒上使用。
我发现了错误,这是由于某种原因没有发送的消息:
fatal error: sharedSession() is not yet implemented: file Foundation/NSURLSession.swift, line 87
0 swift 0x0000000002f4abf8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 swift 0x0000000002f493f6 llvm::sys::RunSignalHandlers() + 54
2 swift 0x0000000002f4b726
3 libpthread.so.0 0x00007fd9dae43d10
4 libswiftCore.so 0x00007fd9d0e5eac3 _TTSf4s_s_s_n___TFs16_assertionFailedFTVs12StaticStringSSS_Su_T_ + 147
5 libFoundation.so 0x00007fd9d3a5c21f
6 libFoundation.so 0x00007fd9d3b178de
7 libFoundation.so 0x00007fd9dbce10c7
8 libFoundation.so 0x00007fd9dbce1079
9 swift 0x0000000000d0da24 llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 996
10 swift 0x0000000000d1102f llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, char const* const*) + 1263
11 swift 0x0000000000bebdf8 swift::RunImmediately(swift::CompilerInstance&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, swift::IRGenOptions&, swift::SILOptions const&) + 2312
12 swift 0x000000000076656e
13 swift 0x0000000000761dfe frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2590
14 swift 0x000000000075d513 main + 2835
15 libc.so.6 0x00007fd9da1e8a40 __libc_start_main + 240
16 swift 0x000000000075c8f9 _start + 41
Stack dump:
0. Program arguments: /usr/bin/swift -frontend -interpret /swift-execution/code-tmp.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -module-name main -lFoundation -lETSocket
/usr/bin/doit.sh: line 19: 10 Illegal instruction timeout 5 swift -lFoundation -lETSocket -v /swift-execution/$fileroot
所以,是的,我们有一些尚未在 Swift 中实现的内容。我将在沙盒的下一个补丁中改进错误消息。
我正在尝试执行以下脚本:
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()
但我收到错误消息:"Error running code: unknown error code 132."。 在 Xcode Playground 中执行代码可以正常工作。
尚未编写 NSURLSession
的纯 Swift 实现。查看 Apple 的 GitHub 基础库中的 NSURLSession.swift
文件。
每个方法都是NSUnimplemented()
,也就是说,嗯,还没有实现。在 class 完成之前,它将无法在 Linux 和 IBM 的 Swift 沙盒上使用。
我发现了错误,这是由于某种原因没有发送的消息:
fatal error: sharedSession() is not yet implemented: file Foundation/NSURLSession.swift, line 87
0 swift 0x0000000002f4abf8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 swift 0x0000000002f493f6 llvm::sys::RunSignalHandlers() + 54
2 swift 0x0000000002f4b726
3 libpthread.so.0 0x00007fd9dae43d10
4 libswiftCore.so 0x00007fd9d0e5eac3 _TTSf4s_s_s_n___TFs16_assertionFailedFTVs12StaticStringSSS_Su_T_ + 147
5 libFoundation.so 0x00007fd9d3a5c21f
6 libFoundation.so 0x00007fd9d3b178de
7 libFoundation.so 0x00007fd9dbce10c7
8 libFoundation.so 0x00007fd9dbce1079
9 swift 0x0000000000d0da24 llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 996
10 swift 0x0000000000d1102f llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, char const* const*) + 1263
11 swift 0x0000000000bebdf8 swift::RunImmediately(swift::CompilerInstance&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, swift::IRGenOptions&, swift::SILOptions const&) + 2312
12 swift 0x000000000076656e
13 swift 0x0000000000761dfe frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2590
14 swift 0x000000000075d513 main + 2835
15 libc.so.6 0x00007fd9da1e8a40 __libc_start_main + 240
16 swift 0x000000000075c8f9 _start + 41
Stack dump:
0. Program arguments: /usr/bin/swift -frontend -interpret /swift-execution/code-tmp.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -module-name main -lFoundation -lETSocket
/usr/bin/doit.sh: line 19: 10 Illegal instruction timeout 5 swift -lFoundation -lETSocket -v /swift-execution/$fileroot
所以,是的,我们有一些尚未在 Swift 中实现的内容。我将在沙盒的下一个补丁中改进错误消息。