Why this happens
Older Objective-C examples use UI_USER_INTERFACE_IDIOM() to distinguish an iPhone-style interface from an iPad-style interface. That function-like macro does not translate into a callable Swift API, so copying it into Swift can produce an Use of unresolved identifier diagnostic.
The Swift replacement is UIDevice.current.userInterfaceIdiom. It returns a UIUserInterfaceIdiom enum value, which you compare with cases such as .phone and .pad. You do not need a bridging header, a third-party device library, or a replacement macro.
There is an important distinction: an interface idiom is not a hardware model or a measurement of available window space. It can tell you that your app uses an iPad-style interface, but it does not tell you whether the current window has enough room for a two-column layout.
How to fix it
1. Replace the macro with the Swift property
Import UIKit in the Swift file that performs the check. Then replace the macro call with the property access:
import UIKit
@MainActor
func configureInterface() {
if UIDevice.current.userInterfaceIdiom == .pad {
print("iPad-style interface")
} else if UIDevice.current.userInterfaceIdiom == .phone {
print("iPhone-style interface")
} else {
print("Another interface idiom")
}
}
The direct replacements are:
UIDevice.current.userInterfaceIdiom == .phonefor an iPhone-style interface.UIDevice.current.userInterfaceIdiom == .padfor an iPad-style interface.UIDevice.current.userInterfaceIdiom == .unspecifiedwhen checking for an unspecified idiom.
Use .pad, not an invented .iPad case. Likewise, use .phone, not .iPhone. Swift infers the enum type from the property on the left side of the comparison.
Notice that userInterfaceIdiom is a property: it has no trailing parentheses. UIDevice.current is also a property rather than a method call.
The example is isolated to the main actor because it accesses UIKit. In an existing view controller or other main-actor UI context, put the comparison directly into the relevant method rather than creating an additional wrapper solely for this check.
2. Use a switch when different idioms need different behavior
The accepted solution also supports switching on the enum. This is clearer when each interface category has its own behavior:
import UIKit
@MainActor
func interfaceDescription() -> String {
switch UIDevice.current.userInterfaceIdiom {
case .phone:
return "Phone-style interface"
case .pad:
return "Pad-style interface"
default:
return "Other interface style"
}
}
Keep a fallback unless you deliberately handle every available case. UIUserInterfaceIdiom contains more than just phone and pad cases, and platform APIs can gain additional cases over time.
A plain default is intentional here: the example groups every other idiom together. Use @unknown default when you explicitly handle the currently known cases and want the compiler to draw attention to newly introduced ones. It is not a substitute for considering known cases that your switch leaves out.
Avoid using a simple else branch to mean “iPhone” after checking only for .pad. “Not pad” does not necessarily mean “phone.” Explicit comparisons make that assumption visible and prevent unrelated interface styles from receiving phone-specific behavior accidentally.
3. In SwiftUI, separate device checks from layout decisions
A SwiftUI view can use the same UIKit property when the requirement genuinely depends on the interface idiom:
import SwiftUI
import UIKit
struct InterfaceLabel: View {
var body: some View {
if UIDevice.current.userInterfaceIdiom == .pad {
Text("Pad-style interface")
} else {
Text("Another interface style")
}
}
}
However, if your real question is “Should these controls appear side by side?”, checking the device category is usually the wrong abstraction. An iPad app can run in a narrow window, and that window can change size while the app is running.
For a simple compact-versus-regular layout, read SwiftUI’s horizontal size class:
import SwiftUI
struct AdaptiveControls: View {
@Environment(\.horizontalSizeClass)
private var horizontalSizeClass
var body: some View {
if horizontalSizeClass == .regular {
HStack {
controls
}
} else {
VStack {
controls
}
}
}
private var controls: some View {
Group {
Button("Save") {
// Save changes.
}
Button("Cancel") {
// Cancel editing.
}
}
}
}
This example responds to the layout environment rather than assuming that every iPad window is wide. The fallback also handles an unspecified size class.
Size classes are broad categories, not exact width measurements. If your content needs a particular amount of room, make that decision from the view’s available space instead. In UIKit, the corresponding size-class information is available through a view or view controller’s traitCollection.
4. Remove screen-size and OS-version workarounds
Some older solutions combine the interface idiom with fixed screen heights to identify individual iPhone or iPad models. That is unnecessary for this fix and fragile as a general device detector.
A screen dimension is not a unique hardware identifier. Fixed values also do not describe the space available to an individual app window. Do not add a table of historical screen heights just to decide between .phone and .pad.
Similarly, there is no need to parse UIDevice.current.systemVersion for an idiom check. When other code genuinely depends on an OS API becoming available, use Swift availability checking:
if #available(iOS 16.0, *) {
// Use an API available on iOS 16 or later.
} else {
// Provide a fallback for earlier deployment targets.
}
Version strings and interface idioms answer different questions. Keeping those checks separate makes the code easier to maintain and avoids treating a dotted version string as a decimal number.
How to prevent it
- Translate Objective-C examples to their Swift APIs rather than copying macros directly.
- Import
UIKitin files that referenceUIDevice. - Check
.phoneand.padexplicitly when those are the categories your feature needs. - Provide a fallback for other interface idioms.
- Use size classes or available view space for adaptive layout.
- Validate layouts in both narrow and wide windows, not only on different device simulators.
- Do not infer a precise hardware model from screen dimensions.
FAQ
Does .pad prove the app is running on physical iPad hardware?
No. It describes an interface idiom, not a hardware identity; Mac Catalyst apps can also use the iPad idiom. Do not use this property alone to distinguish an iPad from a Mac Catalyst environment.
Do I need a device-information package for this?
No. UIKit already provides the phone-versus-pad interface distinction through UIDevice.current.userInterfaceIdiom. A device-information library adds no value for this specific check.
Why is my iPad layout still cramped after checking .pad?
The idiom does not tell you how much space the app window currently has. Keep the idiom check only for interface-category behavior, and use size classes or available width to decide how your content should be arranged.
Parts of this guide are adapted from content licensed under CC BY-SA 3.0; this article is shared under the same license.
