簡體   English   中英

xcodebuild 忽略 #available iOS 版本檢查

[英]xcodebuild ignoring #available iOS version check

嘗試為我的swift package設置 CI。 package 已經運行良好,但我還沒有找到可以成功構建 SampleApp 的xcodebuild命令。

問題似乎是我對 iOS 16 唯一功能.fontWeight(.bold)進行了#available(iOS 16.0, *)檢查。 如果我從 SampleApp 中刪除它,它會構建得很好。 就像xcodebuild忽略了#available(iOS 16.0, *)檢查。 有沒有辦法讓它尊重這張支票?

這是我在項目的根文件夾中使用的命令:

-project SampleApp/ButtonDemo.xcodeproj/ -scheme ButtonDemo clean build -destination 'platform=iOS Simulator,name=iPhone 13 Pro'

這是我得到的錯誤:

/Users/<username>/Dev/CUIExpandableButton/SampleApp/ButtonDemo/ContentView.swift:160:18: error: value of type 'CUIExpandableButton<SFSymbolIcon, some View>' has no member 'fontWeight'
                .fontWeight(.bold)
                 ^~~~~~~~~~
/Users/<username>/Dev/CUIExpandableButton/SampleApp/ButtonDemo/ContentView.swift:160:30: error: cannot infer contextual base in reference to member 'bold'
                .fontWeight(.bold)
                            ~^~~~

代碼片段:

if #available(iOS 16.0, *) {
    CUIExpandableButton(
        expanded: $expanded6,
        sfSymbolName: "exclamationmark.triangle.fill",
        title: "Bolded"
    ) {
        Text("`fontWeight()` can be used to change the entire view.")
        .frame(width: 200)
        .padding(8)
    } action: {
        expanded1 = false
        expanded2 = false
        expanded3 = false
    }
    .fontWeight(.bold)
}

弄清楚發生了什么。 原來#available(iOS 16.0, *)運行時檢查。 所以我需要將它包裝在#if swift(>=5.7)檢查中,這是一個編譯時檢查。 在這里找到了一個很好的解釋: https://www.chimehq.com/blog/swift-and-old-sdks

#if swift(>=5.7)
    if #available(iOS 16.0, *) {
        CUIExpandableButton(
            expanded: $expanded6,
            sfSymbolName: "exclamationmark.triangle.fill",
            title: "Bolded"
        ) {
            Text("`fontWeight()` can be used to change the entire view.")
                .frame(width: 200)
                .padding(8)
        } action: {
            expanded1 = false
            expanded2 = false
            expanded3 = false
        }
        .fontWeight(.bold)
    }
#endif

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM