End of Step 5: Get the ContentView to tell us the OS

xcode15-and-vision
Alan Francis 2 years ago
parent 4ddea12805
commit db8378af6f
  1. 23
      AppShared/ContentView.swift

@ -13,7 +13,16 @@ struct ContentView: View {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
Text("Hello, world!")
#if os(iOS)
Text("Hello \(UIDevice.isIPad ? "iPadOS" : "iOS")")
#elseif os(macOS)
Text("Hello macOS")
#elseif os(tvOS)
Text("Hello tvOS")
#elseif os(watchOS)
Text("Hello watchOS")
#endif
}
.padding()
}
@ -24,3 +33,15 @@ struct ContentView_Previews: PreviewProvider {
ContentView()
}
}
#if os(iOS)
extension UIDevice {
static var isIPad: Bool {
UIDevice.current.userInterfaceIdiom == .pad
}
static var isIPhone: Bool {
UIDevice.current.userInterfaceIdiom == .phone
}
}
#endif

Loading…
Cancel
Save