Issue with @IBOutlet textField: NSTextField!

BNR Team:

I’m working through the chapter and have succesfully completed all the previous steps prior to “Making Connections” however I am having an issue with the first code instruction in this section. First, this is what I have inserted per instructions in the “MainWindowController.swift” file:

@IBOutlet weak var textField: NSTextField!

It is logical to follow along which is why I was stumped by going into the “MainWindowController.xib”, right click on “File Owner’s” under “Placeholders” and not having an option to make the connection with the text field. In the picture that is in the BNR book the top segment of the black box that comes up when you right click has “Outlets” at the top and the first item below that (with an open dot) is “textField” however that is the issue; it does not show after making the code changes to the .swift file.

I would appreciate any advice you have as I’m stumped, have gutted the project and started over twice with the same result at the same milestone. Thank you for your time.


Any chance you defined the textField outlet outside of the MainWindowController class definition? It needs to be between the “class MainWIndowController: NSWindowController {” and the closing brace “}”.


Thank you for your response. I have copied what I have in the script. Thank you for your time.

import Cocoa

class MainWindowController: NSWindowController {
     @IBOutlet weak var textField: NSTextField!
    override func windowDidLoad() {

        // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.

That looks fine. One thing to check: the way the project is set up in the book, the class of File’s Owner should already be MainWindowController. If you ended up renaming anything, that might have changed this, so I’d check to make sure that’s correct. Open MainWindowController.xib, click File’s Owner, and change to the Identity Inspector. Under Class, make sure it says, “MainWindowController”.

If that doesn’t help, are you typing the text in manually from the book? If you are copy/pasting it, such as from an eBook representation, sometimes funny characters can get in there that confuse Xcode.

I believe a hardy thanks and BINGO is in order as that was the fix! See I started the project late after work trying to get my energy down. What I did was originally wrote it as ‘Windwo’ instead of ‘Window’; I thought I had fixed all of those mistakes as it cascaded across the code however I didn’t realize this was still there. As soon as I changed it to ‘Window’ I get the ‘textField’ option. So lesson learned, Identity Inspector has to be checked for accuracy when doing this if you make a mistake in the early coding. Thanks so much, onward we go.


Great news!

I had the same problem. I type fast and sometimes the shift key doesn’t have enough time to come back down before I press the next letter. As a result, I had MainWIndowController (the second “i” was capitalized). Hard to spot error and the spooky thing is that Xcode assumed the misspelling was correct and propagated it all through the project, including in this obscure location in the “Identity Inspector.”

Also, for others coming here, when Adam said “change to the Identity Inspector”, he’s talking about clicking the tiny rectangular icon at the top right end of the screen, just above “Custom Class,” third icon from the left.