Apply SidebarListStyle() to Mac only

In my Catalyst project I'd like to apply `SidebarListStyle()` to Mac only.


My problem is I can't build the project, even when I check for OS. Heres an example:


    struct CrossList: View {
        #if targetEnvironment(macCatalyst)
        var body: some View {
            List {
                Text("Mac Test")
            }
            .listStyle(SidebarListStyle())
        }
        #else
        var body: some View {
            List {
                Text("iOS Test")
            }
        }
        #endif
    }


This gives me the following error when building:


> 'SidebarListStyle' is unavailable in iOS

Accepted Reply

It's not available because you're marking the code as macCatalyst, which is for running iOS apps on macOS, and uses UIKit. The sidebar style is available for macOS apps, as it uses the macOS AppKit framework.

Replies

It's not available because you're marking the code as macCatalyst, which is for running iOS apps on macOS, and uses UIKit. The sidebar style is available for macOS apps, as it uses the macOS AppKit framework.