
- Swift Tutorial
- Swift - Home
- Swift - Overview
- Swift - Environment
- Swift - Basic Syntax
- Swift - Data Types
- Swift - Variables
- Swift - Optionals
- Swift - Tuples
- Swift - Constants
- Swift - Literals
- Swift - Operators
- Swift - Decision Making
- Swift - Loops
- Swift - Strings
- Swift - Characters
- Swift - Arrays
- Swift - Sets
- Swift - Dictionaries
- Swift - Functions
- Swift - Closures
- Swift - Enumerations
- Swift - Structures
- Swift - Classes
- Swift - Properties
- Swift - Methods
- Swift - Subscripts
- Swift - Inheritance
- Swift - Initialization
- Swift - Deinitialization
- Swift - ARC Overview
- Swift - Optional Chaining
- Swift - Type Casting
- Swift - Extensions
- Swift - Protocols
- Swift - Generics
- Swift - Access Control
- Swift Useful Resources
- Swift - Compile Online
- Swift - Quick Guide
- Swift - Useful Resources
- Swift - Discussion
Detect current device with UIUserInterfaceIdiom in Swift
To detect current device with iOS/Swift we can use UserInterfaceIdiom. It is an enum in swift, which tells which device is being used.
The interface idiom provides multiple values in it’s enum which are.
case unspecified @available(iOS 3.2, *) case phone // iPhone and iPod touch style UI @available(iOS 3.2, *) case pad // iPad style UI @available(iOS 9.0, *) case tv // Apple TV style UI @available(iOS 9.0, *) case carPlay // CarPlay style UI
In swift interfaceIdiom can be used in the following way:
print(UIDevice.current.userInterfaceIdiom) if UIDevice.current.userInterfaceIdiom == .phone { print("running on iPhone") }
When we run the above code on an iPhone device following is the result produced.
- Related Articles
- How to detect a mobile device with JavaScript?
- How to detect calls in an android device?
- How to determine device type (iPhone, iPod Touch) with Swift?
- How to detect Spyware on an Android device?
- How to detect shake gesture using Swift?
- How to detect device is Android phone or Android tablet?
- How to Get the current language in Android device?
- How to detect iOS device UDID, Name, Version, Model by programmatically?
- How to detect which iOS version is running on the device?
- How to detect swipe vertically on a ScrollView using Swift?
- How to use Swift to detect when AVPlayer video ends playing?
- How can we get the current language selected in the Android device?
- How to generate Unique ID of device for iPhone/iPad using Swift?
- Detect folders in Safari with HTML5
- Name one device which works on the magnetic effect of current.

Advertisements