Cannot link plugin.py to xib in Xcode

Hello, I am trying to get my hands wet with Xcode. Unsurprisingly, I’m confused. Somehow I am entirely unable to link the IBOutlet() thingies to my xib file. I followed the tutorials on git to the letter but cannot figure out where I’m going wrong. For starters, I get the following:

In Xcode, I’m not sure how it’s supposed to work, but Control-dragging things doesn’t seem to work. When I Control-drag from a checbkox in the xib to File’s Owner, I get a popup only reading “Outlets: formatter, menu, nextKeyView”, but not my IBOutlets I have defined in my plugin.py. I added the plugin class name as the name for the File’s Owner. The plugin.py file is added as a file via “Add File…”.


Screen Recording 2022-08-18 at 01.24.15

Help. Please.

The latest version of Xcode do not work with python files. It doesn’t read the outlet definitions any more. I’ll see what the best workaround is.

If you have access to the current Xcode beta (not sure if you need an Apple Developer account for that), there the bug is fixed.

Or you edit the XML file manually :grimacing:

Haha. I actually tried that and got it to work for one UI element, after half an hour. Then decided it’s probably time invested better otherwise :grin:

If you know what to do, it is only a matter of second. You need to add that one outlet line. Then you can make the connection in Xcode.

I’m working in Xcode 14 beta now. Linking stuff between xib and Python files works! Problem is, there seems to be something wrong with compiling the .xib:

xcode-select: error: tool 'ibtool' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

Any way to compile my xib regardless?

Never mind, there was an issue with my installation directory of Xcode. Works now.

Hello again. I’m having a very annoying issue again. Everything should be working, but for some reason, the link between my text field in the xib and my python plugin doesn’t work.

I have this set up in the plugin.py:

@objc.IBAction
def set_value_(self, sender):
  print(sender.floatValue())

This is linked in Xcode (slightly different names of course):
image
But when changing the value in the UI, nothing happens. Nothing is printed to the macro window, the function is not called. Why?

Edit: no idea what it was in the end, but I used camel case for the action functions, tried out different ways of getting the sender values and wrapping them as str()/float() in python. In any case, it works now.

Always use camel case in selector names. Underscored have a special meaning in pyobjc (they replace the colons and argument positions). Extra ones will mess things up.

Right, thanks. My Python IDE just rightfully complains if I name functions in camel case, that’s pretty much illegal in PEP :wink: Good to know!