0

我在使用 vapor+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

根据状态,这应该没问题。有任何想法吗?

4

1 回答 1

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>
于 2018-05-23T07:01:14.543 回答