Swift, classes, IB

I’ve asked a similar question before. didn’t get a real answer. But now, I need real solid answers. This is a widespread issue for me.


I have a doc based app. Swift.

it has a collection view.

that Collection view (as they do) loads XIB files, as it’s various content views.


None of those XIBs can reference classes defined in my app.

none of them. I don’t get errors, the code just never gets called. It’s like Swift is Spoofing my class, and doing a poor job of it.


they can bind to instances of those classes (i can see property values that are bound, and changing them updates the object,) but the XIB cannot make new instances of a class (as during the normal the behavior of an arrayController,) Actions in these classes can be connected, but they are never called (there’s not even an error message. the class is there, but it isn’t there the method never gets called)


adding @objc(classname) to my class, breaks it even further. the runtime environment reports that the class, has been unceremoniously identified as NSObject, and can not handle its outlets or actions. Nothing at all works.


this is the entirety of one of those classes:

class BKPointMan : NSObject {
   @objc  @IBOutlet weak public dynamic var collectionViewItem: NSCollectionViewItem!
    @objc @IBOutlet weak public dynamic var pointArrayC: NSArrayController!
    @IBAction public func newPoint(_ sender: NSButton) {
        let np = BKPoint(x: 0, y: 0)


as I said, I can make an instance of this class in IB, hook up the outlets and actions. I get no errors, but nothing ever happens. the action is fired, it just never calls the method.


what I’ve done to troubleshoot:

clean, rebuild.

reboot, relaunch.

remove the file reference, re-add it.

check the module settings, the inclusion in the build.

delete the derived data.

re-written the class, wrote multiple brand new classes for testing, imported the class in the document Xib. (that btw, worked just fine. there’s something wrong in the OTHER Xib files.)

Powered by WPeMatico


You may also like...

Comments are closed.