Find if user is using iPAD or iPhone in swift

by sisccr

Many times we have to know if user is on iPad and iPhone. The most simple example is showing alerts and actionSheet. ActionSheets are cool when you have a bunch of actions. But iPad doesn’t support ActionSheets. In such case we may show alerts in iPad and actionSheet in iPhone.


UIAlertControllerStyle determines how the alerts are shown.

var presentationStyle: UIAlertControllerStyle = .ActionSheet
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.Pad) {
            presentationStyle = .Alert
            // Looks like user is using iPad...
        // now show alerts using presentationStyle. and forget what device user is using.