使用steam + Xcode进行编译时遇到了这个编译问题:
以下是一些相关信息:
$ vapor --version
Vapor Toolbox: 3.1.7
Vapor Framework: 3.0.1
$ swift --version
Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1)
Target: x86_64-apple-darwin17.6.0
根据the status,这应该没问题。有什么想法吗?
答案 0 :(得分:1)
在MacOS上,无法构建
$ swift --version
Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1)
Target: x86_64-apple-darwin17.5.0
$ mkdir MyExec
$ cd MyExec
$ swift package init --type executable
$ swift package update
$ vim Sources/MyExec/main.swift
import Foundation
import CoreFoundation
let timer = Timer.scheduledTimer(withTimeInterval: 3, repeats: true) { timer in
print("\(timer)")
}
print("\(timer)")
CFRunLoopRun()
$ swift build
Compile Swift Module 'MyExec' (1 sources)
/path/MyExec/Sources/MyExec/main.swift:4:19: error: 'scheduledTimer(withTimeInterval:repeats:block:)' is only available on OS X 10.12 or newer
let timer = Timer.scheduledTimer(withTimeInterval: 3, repeats: true) { timer in
^
/path/MyExec/Sources/MyExec/main.swift:4:19: note: add 'if #available' version check
let timer = Timer.scheduledTimer(withTimeInterval: 3, repeats: true) { timer in
^
error: terminated(1): /Library/Developer/CommandLineTools/usr/bin/swift-build-tool -f /path/MyExec/.build/debug.yaml main output:
在Ubuntu上,正在工作
$ swift --version
Swift version 4.1 (swift-4.1-RELEASE)
Target: x86_64-unknown-linux-gnu
$ mkdir MyExec
$ cd MyExec
$ swift package init --type executable
$ swift package update
$ vim Sources/MyExec/main.swift
import Foundation
import CoreFoundation
let timer = Timer.scheduledTimer(withTimeInterval: 3, repeats: true) { timer in
print("\(timer)")
}
print("\(timer)")
CFRunLoopRun()
$ swift build
$ .build/x86_64-unknown-linux/debug/MyExec
<Timer: 0x000055aeb1cf6790>
<Timer: 0x000055aeb1cf6790>
<Timer: 0x000055aeb1cf6790>