Skip to content

Instantly share code, notes, and snippets.

@gewill
Created December 5, 2022 05:29
Show Gist options
  • Save gewill/55df11194e5e469555a9718cdf565366 to your computer and use it in GitHub Desktop.
Save gewill/55df11194e5e469555a9718cdf565366 to your computer and use it in GitHub Desktop.
UserInterfaceIdiom for all Apple platforms or devices.
enum UserInterfaceIdiom: Int {
case unspecified = -1
case phone = 0
case pad = 1
case tv = 2
case carPlay = 3
case mac = 5
case watch = 6
static var current: UserInterfaceIdiom {
#if os(iOS)
UserInterfaceIdiom(rawValue: UIDevice.current.userInterfaceIdiom.rawValue) ?? .unspecified
#elseif os(macOS)
return .mac
#elseif os(watchOS)
return .watch
#elseif os(tvOS)
return .tv
#else
return .unspecified
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment