Search code examples
swiftxcodeiboutletibactionxcode-storyboard

Storyboard not linking to @IBAction/Outlet in ViewController.swift Xcode


I'm trying to link an element in an Xcode Storyboard to an @IBAction or @IBOutlet but when I drag-and-drop in the assistant editor I cannot place the connection. The blue line does not settle, just hovers. Even if I try to manually connect (by typing @IBAction func test(_ sender: Any){} the little circle to the left does not settle. I've tried to use (_ sender: NSButton) {} but even that does not work.
This is making me lose time, and not being able to reference an NSButton out of storyboards is just not helpful!!
I don't know if this is an Xcode 9 bug, yet most others don't have this issue. I’ve looked at other SO questions but they are mostly for iOS/UIKit, not for Cocoa Frameworks and the answers haven't worked for me anyway.

I'm developing in Xcode 9, Swift 4 and for Mac
Thanks in advance!


Solution

  • Most probably you didn't set the ViewController class in the storyboard.

    1. Select story board
    2. Select the Viewcontroller
    3. Select Identity inspector

    enter image description here

    1. Enter your ViewController classe's name
    2. Now try and link it again.