我FileHandle.read(upToCount:)在 macOS 10.15.7 上使用時遇到問題;每當我嘗試這樣做時,都會收到以下錯誤:
error: 'read(upToCount:)' is only available in macOS 10.15.4 or newer
這個約束與我可以看到的相匹配:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/swift/Foundation.swiftmodule/x86_64.swiftinterface
extension FileHandle {
...
@available(OSX 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *)
public func read(upToCount count: Swift.Int) throws -> Foundation.Data?
...
}
我可以通過一個小測驗來復制這個可用性問題;像main.swift這樣:
@available(OSX 10.15.4, *)
func test() {}
test()
這給了我同樣的一般錯誤:
error: 'test()' is only available in macOS 10.15.4 or newer
如果我將@available約束更改為OSX 10.15或者OSX 10.15.0這編譯正常,但OSX 10.15.1或更高版本將報告相同的錯誤,這似乎表明工具鏈認為構建目標是 10.15.0。不過,看看swiftc幕后所做的事情,它似乎使用了正確的 SDK 和三元組:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift \
-frontend \
-c \
-primary-file main.swift \
-target x86_64-apple-darwin19.6.0 \
-enable-objc-interop \
-stack-check \
-sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk \
-color-diagnostics \
-target-sdk-version 11.1 \
-module-name main \
-o /var/folders/ml/3hynjc6s5v96y4k_wfy3gt6r0000gn/T/main-9906ee.o
任何人都可以對正在發生的事情有所了解,以及我可以做些什么來說服我的工具鏈相信這些功能可供我構建?
uj5u.com熱心網友回復:
簡短的回答
利用:
-target x86_64-apple-macos10.15.7
長答案
正如@Willeke 所建議的那樣,看看 Xcode 做了什么讓我走上了正確的道路。Xcode 中的一個新命令列專案通過:
-target x86_64-apple-macos10.15
到編譯時的 Swift 后端,由于@available約束仍然失敗,但將其修改為:
-target x86_64-apple-macos10.15.7
按預期作業。
令人討厭的是,在三元組中使用相應darwin版本不會導致與使用macos版本相同的行為,但我想這是由于只有一個基于達爾文的作業系統出現的時代遺留下來的蘋果。現在,給定的 Darwin 版本可能意味著不同版本的 macOS、iOS、tvOS 等,每個版本都有不同的可用 API 集。??
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/496702.html
