Post

Replies

Boosts

Views

Activity

Compiler directives in SwiftUI for platform-specific attributes
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: 				NavigationView { 						... 				}         #if os(iOS)			 				.navigationViewStyle(StackNavigationViewStyle())         #endif
4
0
6.7k
Jul ’21
Compiler directives in SwiftUI for platform-specific attributes
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: 				NavigationView { 						... 				}         #if os(iOS)			 				.navigationViewStyle(StackNavigationViewStyle())         #endif
Replies
4
Boosts
0
Views
6.7k
Activity
Jul ’21