В 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>