Reputation: 81
I would like to navigate to a different view depending on target (iOS, macOS, watchOS, etc.). How would I achieve this in SwiftUI?
I also need to avoid "Cannot find 'WatchView' in scope" error as WatchView does not share the same Target Membership as iOSView.
Example:
var body: some View {
if #available(iOS 14, *) {
iOSView()
} else if #available(watchOS 2, *) {
WatchView()
}
}
Upvotes: 0
Views: 27
Reputation: 81
As Asperi and jnpdx stated, it needed to be #if
:
var body: some View {
#if os(watchOS)
WatchView()
#else
iOSView()
#endif
}
Upvotes: 1