swiftxcodeios-universal-app

Different Launch functions for iPad than for iPhone (in Swift 3)?


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?


Solution

  • 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"