1

I'm trying to trigger a function in my universal iOS app for iPad only. It shows a set of background images on the iPad version of the app, but I don't want that function to run in the iPhone version.

So this needs to happen in code, and I was thinking it would probably go into the viewDidLoad() section, I was hoping I wouldn't have to create two separate view controllers?

Is there a simple if REGULAR height && REGULAR width kind of expression?

Brewski
  • 654
  • 3
  • 14
  • 29

1 Answers1

3

You can just check the type with UIDevice

if UIDevice().model == "iPad" {
   // do iPad things
} else {
   // do iPhone things
}

explanation:

open var model: String { get } // e.g. @"iPhone", @"iPod touch"
Willjay
  • 6,381
  • 4
  • 33
  • 58
  • 1
    This is a bad idea. What about when the app in being run on an iPad but in multitasking mode? Then the app will be sized much like an iPhone app but on the iPad. Decisions should be based on view size, not device type. – rmaddy Jan 03 '17 at 06:57
  • @rmaddy You are probably right in most cases but this worked for me in this specific application. – Brewski Jan 04 '17 at 06:23