Failed to connect (storyboard) outlet from (NSApplication) to (NSNibExternalObjectPlaceholder) error in Cocoa and storyboard

20,903

Solution 1

While the answer above correctly states that this isn't the reason for compilation issues, I thought that I would clarify for those who are just looking to eliminate the warning messages altogether. This was what I was looking for when I found this page.

When you are building your actions and some of the actions change, or get deleted in the storyboard, the outlets remain. Select the controller/window where the older unused actions used to be and you will still see them in the outlets segment of the storyboard within the attributes tab. Remove those old actions/outlets there and then the warning disappear.

Look for duplicates between the ViewController and the File's Owner. One or both might be holding on to these objects when they shouldn't be. Removing those will remove these soft warnings.

Solution 2

Failed to connect (storyboard) outlet from (NSApplication) to (NSNibExternalObjectPlaceholder): missing setter or instance variable

The IBAction methods working like it should, see Apple Dev Forums:

"This is a known issue ... The messages are harmless and do not indicate a problem with your code."

Apple Dev Forums: OS X Storyboard failure

Thats not why your code is not working, you need to fix the following:

A) Here is my working code to set the title - using self.view.window.title instead self.title:

@IBAction func btnSetWindowTitle(sender : AnyObject) {
    if self.txtTitle.stringValue != "" {
        println(self.view.window.title)
        println(self.txtTitle.stringValue)
        self.view.window.title = self.txtTitle.stringValue
    }
}

B) In Interface Builder you need to set NSBox "Box Type" to "Custom": enter image description here

And that's it: enter image description here

Solution 3

I think I figured out the right solution.

enter image description here

1) Drag an Object into you xib interface.

enter image description here

2) Click the Object in the left list you just dragged in.

enter image description here

3) Bind the Object to your custom class.(Here my class is a login window controller as example)

enter image description here

4) Ctrl drag button to the source code. In the popup window, choose your class name(here in example is Login Window Controller) rather than File's Owner.

Hope this could help you.

Solution 4

I've found another easier solution these days while coding.

Check this out.

enter image description here

1) Select File's Owner in Document Outline in the .xib file.

enter image description here

2) Specify the class you want the .xib file to connect with.

enter image description here

3) Now when you connect outlet to the source file, just use default File's Owner. Much easier.

enter image description here enter image description here

4) I guess it's not enough so far. I've met an exception when running called 'loaded the 'xxx' nib but the view outlet was not set'. We should do something more.

Select the view in Document Outline. Drag from the circle of New Referencing Outlet to the File's Owner in Document Outline.

Alright, that's the new easier solution. No additional objects should add into the xib. If it doesn't work, leave comments below.

Share:
20,903
Blaszard
Author by

Blaszard

I'm here to gain knowledge and insights on a variety of fields I'm interested in. Specifically, Programming & Software Development (Python and R; no longer use Swift and JavaScript/node.js) Data Science, Machine Learning, AI, & statistics Travel (started in 2016) Language (普通话, français, español, italiano, русский, 한국어) Politics, Economics, and Finance Currently (in 2020), my primary interest is Korean and Russian😈 PS: I'm not a native-English speaker. If you find any errors in my grammar and expressions, don't hesitate to edit it. I'll appreciate it👨🏻‍💼

Updated on July 09, 2022

Comments

  • Blaszard
    Blaszard almost 2 years

    I've tried to build a sample Cocoa app on which I want to connect UI components put on storyboard to ViewController.swift as either an IBOutlet or IBAction. However, when I tried to control-drag the UI components on storyboard (such as NSButton) to ViewController.swift and create a @IBAction method, and then run the app, the resultant app logs the following message in console and of course the app doesn't respond to me tapping the button.

    Failed to connect (storyboard) outlet from (NSApplication) to (NSNibExternalObjectPlaceholder): missing setter or instance variable
    

    How can I use the IBAction method properly?

    For your information here's my ViewController.swift:

    import Cocoa
    
    class ViewController: NSViewController {
        @IBOutlet var txtTitle : NSTextField
        @IBOutlet var boxColor : NSBox
    
        override func viewDidLoad() {
            super.viewDidLoad()
        }
    
        func colorChanged(cp: NSColorPanel) {
            let c:NSColor = cp.color;
            self.boxColor.fillColor = c
        }
    
        @IBAction func btnSetColor(sender : AnyObject) {
            let cp:NSColorPanel = NSColorPanel.sharedColorPanel()
            cp.setTarget(self)
            cp.setAction("colorChanged:")
            cp.orderFront(nil)
    
        }
    
        @IBAction func btnSetWindowTitle(sender : AnyObject) {
            if self.txtTitle.stringValue != "" {
                println(self.title)
                println(self.txtTitle.stringValue)
                self.title = self.txtTitle.stringValue
            }
        }
    }
    

    I use Xcode 6 beta on OS X 10.10 Yosemite. And started the template with storyboard being on.