Harangue Harangue - 1 year ago 378
Swift Question

iOS custom keyboard with storyboard

I'm trying to make a simple iOS custom keyboard extension using Swift. The default UIView wasn't meeting my needs, so I read on this SO question that I could use a storyboard with the

property in

Unfortunately every time I open my keyboard, I get the following errors

2016-01-18 18:02:56.350 Kappa Keyboard[44790:2959180] Failed to inherit CoreMedia permissions from 44787: (null)
2016-01-18 18:02:56.368 Kappa Keyboard[44790:2959138] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
0 CoreFoundation 0x002f1746 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01d32a97 objc_exception_throw + 44
2 CoreFoundation 0x001a6ce1 -[__NSArrayM insertObject:atIndex:] + 881
3 CoreFoundation 0x001a6941 -[__NSArrayM addObject:] + 65
4 UIKit 0x00c7d0bd -[UIViewController _addChildViewController:performHierarchyCheck:notifyWillMove:] + 417
5 UIKit 0x00c968aa -[UIViewController(UIContainerViewControllerProtectedMethods) addChildViewController:] + 78
6 UIKit 0x01206db8 -[_UIViewServiceViewControllerOperator __createViewController:withContextToken:fbsDisplays:appearanceSerializedRepresentations:legacyAppearance:traitCollection:initialInterfaceOrientation:hostAccessibilityServerPort:canShowTextServices:replyHandler:] + 2702

The stack trace continues on, but that's the gist of it.

Here's all I've done (I tried this in a clean project).

  1. Create container app

  2. Create Keyboard target

  3. Add Main.storyboard

  4. Add
    NSExtension.NSExtensionMainStoryboard: Main
    to info.plist

  5. Set
    's custom class to the default

Any idea what I'm missing?

Answer Source

Add a storyboard file to your keyboard target.
In your keyboard target's general tab, make Main Interface to your storyboard file like in the screenshot.
The second important part is making sure to change your KeyboardViewController reference's view's class to UIInputView instead of UIView in storyboard.

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download