0

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)
}
robhasacamera
  • 2,967
  • 2
  • 28
  • 41
  • Please show the code snippet, where `.fontWeight(.bold)` is used. – lazarevzubov Jul 28 '22 at 07:14
  • 1
    @lazarevzubov - Added the snippet. There’s also a link to the package if you need to look at any of the other code. – robhasacamera Jul 28 '22 at 07:41
  • I look at the `CUIExpandableButton` implementation and don't see where `fontWeight` is declared for this type. – lazarevzubov Jul 28 '22 at 19:00
  • 1
    It's part of the iOS 16 Beta. In the beta you can apply fontweighp to any view and it'll be inherited by it's children. Documentation is here: https://developer.apple.com/documentation/swiftui/list/fontweight(_:) – robhasacamera Jul 29 '22 at 01:13

1 Answers1

0

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
robhasacamera
  • 2,967
  • 2
  • 28
  • 41