SwiftUI multi platform incompatibilities

Developing a multi platform app using SwiftUI. But soon ran into compile issues on macOS because of EditMode incompatibility on that platform. EditMode is quite intensively used almost in every scene in iOS and also deeply ingrained in modifier calls etc.

It is apparent the power and the potential of SwiftUI in developing complex apps and its multi platform support.

However I am a bit surprised about the cross-platform cross platform incompatibility of basic facets like EditMode. So surprised that I am questioning myself if I am doing it right. Is there a way to develop cross platform apps using SwiftUI without extensive use of preprocessor directives strewn across "shared" code?


Answered by fractal in 624601022
I'm a swiftUI newbie, but so far my experience has been that your cross-platform swiftUI views will be full of
Code Block
#if os(...)


And for modifiers, I guess you have to do something like this, which makes it even more annoying
Code Block
/// Workaround since .collapsible isn't available on iOS and there's no way to #if out the modifier function directly
extension Section where Parent: View, Content: View, Footer: View {
    func noCollapseIOSCompat() -> some View {
        #if os(macOS)
        return self.collapsible(false)
        #else
        return self
        #endif
    }
}


Accepted Answer
I'm a swiftUI newbie, but so far my experience has been that your cross-platform swiftUI views will be full of
Code Block
#if os(...)


And for modifiers, I guess you have to do something like this, which makes it even more annoying
Code Block
/// Workaround since .collapsible isn't available on iOS and there's no way to #if out the modifier function directly
extension Section where Parent: View, Content: View, Footer: View {
    func noCollapseIOSCompat() -> some View {
        #if os(macOS)
        return self.collapsible(false)
        #else
        return self
        #endif
    }
}


I too am stunned by the lack of support for EditMode on MacOS. I too thought I was doing it wrong. Maybe I still am.

Nobody from Apple has bothered to respond to this post or mine from a few days ago.

How about a little official guidance Apple?
SwiftUI multi platform incompatibilities
 
 
Q