Can SwiftUI compile on both Mac and iOS

I understand there are many differences between Mac and iOS, but with Macs getting native iOS app support and the two platforms being similar more than ever, I wonder if it is possible to make a singular SwiftUI and then compile it for both, or must I still make a new one for each?
Answered by OOPer in 614473022
Have you tried Xcode 12 beta?
You can create a Multiplatform/App project.

You just need to write the same code and compile it for both for a simple app.

In a practical app, you may need to add some platform specific features, but you can share most parts of code in common with iOS and macOS.
Accepted Answer
Have you tried Xcode 12 beta?
You can create a Multiplatform/App project.

You just need to write the same code and compile it for both for a simple app.

In a practical app, you may need to add some platform specific features, but you can share most parts of code in common with iOS and macOS.
As OOPer (nice name 😊) mentions, the recommended path for brand new apps is following the new Multiplatform App template, which gives you the best of both worlds: (1) you can share code code by default between the Mac and iOS app, taking advantage of the automatic support SwiftUI provides for both platforms; and (2) when needed you can specialize for one platform or the other, such as adding support for a settings window on macOS or optimized UIs for touch on iOS.

The automatic support for iPhone and iPad apps to run on the Mac will not be quite as optimized for the Mac as what an explicit SwiftUI app on the Mac can provide.
how do I add platform specific code? :) see also https://developer.apple.com/forums/thread/651876
Can SwiftUI compile on both Mac and iOS
 
 
Q