How to Detect iPad vs iPhone in Swift and SwiftUI

How to Detect iPad vs iPhone in Swift and SwiftUI

Written by

in

Quick answer: Check UIDevice.current.userInterfaceIdiom == .pad for iPad and == .phone for iPhone. In Objective-C use UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad. Avoid checking UIDevice.model strings.

If your app runs on both iPhone and iPad you often need a small branch: a different layout, a popover instead of a sheet, or a larger asset. Checking the device idiom is the correct way to do it, not the device name or screen size.

Why this happens

iOS distinguishes devices by interface idiom, not by model name. An idiom tells you what kind of UI the system expects: .phone for iPhone and iPod touch, .pad for iPad, .tv for Apple TV, .carPlay for CarPlay, and .unspecified for other contexts.

This matters because an iPhone-only app can still run on an iPad in compatibility mode. In that case UIDevice.current.model may report “iPad” while the interface idiom is still .phone if the app is not built as Universal. If you branch on the model string you will get the wrong behavior. Checking userInterfaceIdiom tells you how UIKit will actually present your view controllers.

Screen size is also unreliable. iPads and large iPhones overlap in points, and multitasking, Split View, and Stage Manager change the available size at runtime. Idiom plus trait collections gives you a stable, Apple-supported signal.

How to fix it

Use userInterfaceIdiom in Swift and UI_USER_INTERFACE_IDIOM() in Objective-C. In SwiftUI, prefer the same check or adapt with trait collections when you care about available space rather than the device type.

1. Check idiom in Swift (recommended for UIKit and SwiftUI logic)

This is the modern Swift equivalent of the accepted Objective-C answer and works in any Universal app.

import UIKit

if UIDevice.current.userInterfaceIdiom == .pad {
    // iPad-specific logic
} else if UIDevice.current.userInterfaceIdiom == .phone {
    // iPhone / iPod touch logic
}

// You can also switch over all cases:
switch UIDevice.current.userInterfaceIdiom {
case .pad:
    print("iPad")
case .phone:
    print("iPhone")
case .tv:
    print("Apple TV")
case .carPlay:
    print("CarPlay")
case .vision:
    print("visionOS")
case .mac:
    print("Mac Catalyst")
case .unspecified:
    print("unspecified")
@unknown default:
    print("unknown")
}

Put this in your UIViewController when you need to adjust behavior:

import UIKit

class DetailViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        if UIDevice.current.userInterfaceIdiom == .pad {
            // Use a wider layout, show a side panel, or configure a popover
            preferredContentSize = CGSize(width: 600, height: 800)
        }
    }
}

For a reusable helper, add a small extension:

import UIKit

extension UIDevice {
    static var isIPad: Bool {
        UIDevice.current.userInterfaceIdiom == .pad
    }
    static var isIPhone: Bool {
        UIDevice.current.userInterfaceIdiom == .phone
    }
}

// Usage
if UIDevice.isIPad {
    // do iPad work
}

2. Check idiom in Objective-C

If your codebase is still Objective-C, use the UI_USER_INTERFACE_IDIOM() macro. It is a wrapper around [[UIDevice currentDevice] userInterfaceIdiom].

#import <UIKit/UIKit.h>

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    // Device is iPad
} else {
    // Device is iPhone or iPod touch
}

The common macro pattern from the accepted answer still works:

#define IDIOM UI_USER_INTERFACE_IDIOM()
#define IS_IPAD (IDIOM == UIUserInterfaceIdiomPad)

if (IS_IPAD) {
    // iPad-specific code
}

Or without a macro:

if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
    // iPad
}

3. Adapt in SwiftUI with idiom or trait collections

In SwiftUI you can use the same UIDevice check, but often you want to adapt to available space instead of the device model. Use both where appropriate.

Option A: Direct idiom check (when you truly need device type):

import SwiftUI

struct ContentView: View {
    var body: some View {
        Group {
            if UIDevice.current.userInterfaceIdiom == .pad {
                IPadLayout()
            } else {
                IPhoneLayout()
            }
        }
    }
}

Option B: Trait collections / size classes (when you care about layout):

import SwiftUI

struct AdaptiveView: View {
    @Environment(\.horizontalSizeClass) private var horizontalSizeClass
    @Environment(\.verticalSizeClass) private var verticalSizeClass

    var body: some View {
        if horizontalSizeClass == .regular && verticalSizeClass == .regular {
            // Large canvas - typically iPad fullscreen
            HStack {
                SidebarView()
                DetailView()
            }
        } else {
            // Compact - typically iPhone or iPad Split View narrow
            NavigationStack {
                DetailView()
            }
        }
    }
}

You can also read the trait collection from UIKit if you are in a UIViewController:

if traitCollection.userInterfaceIdiom == .pad {
    // iPad trait
}

This is useful inside traitCollectionDidChange(_:) when the user enters Split View and the size class changes without the idiom changing.

4. Avoid checking the model string

You will see this pattern in older code:

// Fragile - do not use
if (UIDevice.current.model as NSString).hasPrefix("iPad") {
    // iPad
}

Or in Objective-C:

// Fragile - do not use
if ([[UIDevice currentDevice].model hasPrefix:@"iPad"]) {
    // iPad
}

This breaks for future device names, localized models, simulators, and Mac Catalyst where the model may be “Mac”. It also cannot distinguish an iPhone-only app running on iPad. Apple documents userInterfaceIdiom as the supported API for this decision, so use it.

If you need to know the exact hardware for analytics, use utsname or a well-maintained device-identification library, but never branch UI on it.

How to prevent it

  • Build your app as Universal when you support iPad and test both idioms in the simulator (iPhone SE and iPad Pro).
  • Branch UI on userInterfaceIdiom or traitCollection.userInterfaceIdiom, not on UIDevice.model, UIScreen.bounds, or hard-coded widths.
  • For layout, prefer horizontalSizeClass / verticalSizeClass and GeometryReader over device checks. Reserve idiom checks for behavior that is truly device-specific, like popover presentation or Pencil support.
  • Add a helper like UIDevice.isIPad so the check is consistent and searchable, and avoid scattering macros or string checks.
  • Test multitasking: run your iPad layout in Split View 1/3 and 2/3 widths to ensure size-class logic still works.

FAQ

Is UIDevice.current.userInterfaceIdiom reliable on iPad and Mac Catalyst?

Yes. On iPad it returns .pad, on iPhone .phone, on Mac Catalyst .mac, and on visionOS .vision. It reflects the idiom the system uses to present your UI. For Catalyst, check for .pad and .mac if you share code between iPad and Mac.

Should I use userInterfaceIdiom or horizontalSizeClass in SwiftUI?

Use userInterfaceIdiom when the feature is tied to the device family, such as showing a popover on iPad or enabling Apple Pencil interactions. Use horizontalSizeClass when the decision is about available space, such as switching between a sidebar and a tab bar. Many apps use both.

How do I test iPad detection without a physical iPad?

In Xcode, run your scheme on an iPad simulator from the device list. You can also use Preview variants in SwiftUI: .previewDevice(PreviewDevice(rawValue: "iPad Pro (12.9-inch)")) or the canvas device selector. For UIKit, set the run destination to iPad and verify both fullscreen and Split View.

Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.