How to: Build A Cross-Platform App with SwiftUI 2
Let me show you how to build a simple app that works on iOS, iPadOS, and macOS…

How to know the device is running iOS / macOS?
We can use:
#if os(iOS) //For iPhone/iPad
…#elseif os(macOS) //For Mac
…#elseif os(watchOS) //For WatchOS
…#endif
If you want to divide iPhone and iPad design, before
var body: some Viewadd the following code,
@Environment(\.horizontalSizeClass)
private var horizontalSizeClassand then add,
if horizontalSizeClass == .compact //For iPhoneafter
var body: some ViewExample:
import SwiftUIstruct ContentView: View {
#if os(iOS)
@Environment(\.horizontalSizeClass)
private var horizontalSizeClass
#endifvar body: some View {
#if os(iOS)
if horizontalSizeClass == .compact //For iPhone
{
Text(“Hello! iPhone.”)
}else //For iPad
{
Text(“Hello! iPad.”)
}#else //For Mac
Text(“Hello! Mac.”)#endif} }






