这是我的代码:
import Foundation
if let utc = TimeZone(abbreviation: "UTC") {
let calendar = Calendar.current
print("\(calendar.description)")
print("Before dateComponents")
let componentsDate1 = calendar.dateComponents(in: utc, from: Date())
print("\(componentsDate1)")
}
else {
print("Could not create timezone")
}
我在Docker下的Ubuntu 16.04上运行。结果是:
gregorian (current)
Before dateComponents
Segmentation fault
看来dateComponents调用崩溃了。
我的Docker容器基于 https://github.com/apple/swift-docker/blob/0aafffef619fb3b1824c968cbbe2fba4ba41bd26/5.0/ubuntu/16.04/Dockerfile
建议?
更新 1)我刚刚在虚拟机下运行的Ubuntu 16.04系统上复制了此文件,并安装了适用于Ubuntu 16.04的Swift 5.0.1版本:https://swift.org/builds/swift-5.0.1-release/ubuntu1604/swift-5.0.1-RELEASE/swift-5.0.1-RELEASE-ubuntu16.04.tar.gz
答案 0 :(得分:0)
我刚刚得知这确实是一个已知错误,并且具有已知的当前修复程序: https://forums.swift.org/t/possible-bug-in-datecomponents-method-running-on-ubuntu-16-04/25702