I am working on a custom keyboard and if i include this code in my class the i got the error:

let isPad = UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad

Error - Command/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

I need this code because when user runs iPhone app (like instagram) on iPad, I need to load iPhone keyboard preset and use its geometry. I have try below code but it is not a solution:

if UI_USER_INTERFACE_IDIOM() == .Pad {

}

So please share if anyone have any solution.

Error screen shot

1

There are 1 best solutions below

1
On

Try this:

if UIDevice.currentDevice().userInterfaceIdiom == .Pad {

    // iPad Stuff
}

else if UIDevice.currentDevice().userInterfaceIdiom == .Phone {

    // iPhone Stuff
}

EDIT

Swift 3

if UIDevice.current.userInterfaceIdiom == .pad {

    // iPad Stuff
}

else if UIDevice.current.userInterfaceIdiom == .phone {

    // iPhone Stuff
}