I'm building a universal application with SwiftUI that has an iOS app and Share Extension as well as a macOS app and Share Extension.
There's a few places where I'm using SwiftUI attributes that are iOS-specific (example a NavigationView that has a StackNavigationViewStyle attribute) and need to provide an alternative when running on macOS.
My question is: How do I ensure that these attributes that are only available for one platform don't cause build issues for the other platform? I've tried using the #if os(iOS) compiler directive, but then I get a build error saying "Unexpected platform condition (expected 'os' 'arch' or 'swift')" when doing something like this:
There's a few places where I'm using SwiftUI attributes that are iOS-specific (example a NavigationView that has a StackNavigationViewStyle attribute) and need to provide an alternative when running on macOS.
My question is: How do I ensure that these attributes that are only available for one platform don't cause build issues for the other platform? I've tried using the #if os(iOS) compiler directive, but then I get a build error saying "Unexpected platform condition (expected 'os' 'arch' or 'swift')" when doing something like this:
Code Block swift NavigationView { ... } #if os(iOS) .navigationViewStyle(StackNavigationViewStyle()) #endif
I believe this feature was added in Swift 5.4 Swift by sundell has an article about it.