Connecting nib to KeyboardViewController.Swift

I tried to connect a nib to my KeyboardViewController.Swift using these lines of code:

class KeyboardViewController: UIInputViewController{
let nib = UINib(nibName: "FBK8", bundle: nil)
    let objects = nib.instantiateWithOwner(self, options: nil)
view = objects[0] as! UIView

When I use control-click to drag something on my FBK8.xib to the KeyboardViewController.Swift there is nothing I can do. Does anybody have a solution? Thank you!

It's not clear why you're taking this approach, as the normal approach is much easier.


1. Why not use the inherited UIViewController initializer 'initWithNibName:bundle:' to connect your view controller to the NIB? I don't see any value in re-inventing this wheel. However, I don't see anything particularly wrong in doing it your way.


2. The link between your programmatically created view controller and the loaded view is "…WithOwner(self…). That is, your view controller will be "File's Owner" in your XIB file, and you should set the class of that pseudo-object to KeyboardViewController.


3. If you want to bind from UI elements in the XIB file through the view controller, use File's Owner. Similarly, if you want to connect something (e.g. a delegate) from a UI element to the view controller, use File's Owner as the destination.


4. For other purposes, you have to go in the other direction. Set up @IBOutlets in KeyboardViewController, and connect them in the XIB from File's Owner to the relevant UI element. The nib loading process should set the values of the outlets in your view controller.


5. I may have missed something, but I think those are the only mechanisms for control-dragging that are generally available. If you want to control-drag and auto-create outlets and actions, once you've set the correct class for Files's Owner (step 2), IB should let you do this as usual.

Connecting nib to KeyboardViewController.Swift
 
 
Q