4

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

VSP
  • 166
  • 11
  • 1
    I have exactly the same issue. Still no solution. – Maria Sep 02 '15 at 07:29
  • @Maria I think UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad is not supported with a type of UIInputViewController class it is supported to UIViewController class .I still not get any solution for that but i use another method for it may be it is useful for you override func viewWillLayoutSubviews() { } this method give me exact size of default keyboard in some attempt so i use it and do my code according to it.. – VSP Sep 02 '15 at 09:52
  • My issue was that I accidently left old UI_USER_INTERFACE_IDIOM() == .Pad instead of proper UIDevice.currentDevice() in one file. I used xctool to find that https://github.com/facebook/xctool because xcode error message was not very informative. – Maria Sep 02 '15 at 10:59

1 Answers1

3

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
}
Brandon A
  • 8,153
  • 3
  • 42
  • 77
  • 2
    This worked for me. I've no idea why this issue started - UI_USER_INTERFACE_IDIOM seemed to work fine previously. – Ian Dec 24 '15 at 19:59