xcodebuild ignoring #available iOS version check

691 Views Asked by At

Trying to setup CI for my swift package. It's already running fine for the package but I haven't found a xcodebuild command that will build the SampleApp successfully.

The issue seems to be that I have a #available(iOS 16.0, *) check around a iOS 16 only feature, .fontWeight(.bold). If I remove this from the SampleApp it builds fine. It's like xcodebuild is ignoring the #available(iOS 16.0, *) check. Is there a way to get it to respect this check?

Here is the command I'm using from the root folder of the project:

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

The is the error I'm getting:

/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)
                            ~^~~~

Code Snippet:

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)
}
1

There are 1 best solutions below

0
robhasacamera On

Figured out what was happening. Turns out that #available(iOS 16.0, *) is a runtime check. So I needed to wrap this in an #if swift(>=5.7) check which is a compile time check. Found a pretty good explanation for it here: 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