Skip to content
This repository

Can't connect to Outlets/Actions #135

Closed
Watson1978 opened this Issue · 36 comments
Watson
Owner

I use OSX 10.8 and Xcode 4.4.1.
In the past, when opened the xib files in Xcode projects at everytime, Xcode invoked rb_nibtool.
However, now it seems that Xcode invokes only it at opening the project.

So, It needs to reopen project to connect to Outlets/Actions after inserting attr_accessor or methods.

Joshua Ballanco
Owner

Hmm... I only see 3 things that we can do here:

  1. Report this as a bug to Apple and hope they fix it.
  2. Write a synthetic header-generator that creates corresponding *.h files to trick Xcode into thinking that we're using ObjC. (You would still have to run this every time after modifying your Ruby classes, but we could use something like kicker for that...)
  3. Forget about Xcode integration and/or work on integrating with AppCode from JetBrains (http://www.jetbrains.com/objc/).

I think the best course would be some combination of all 3...

Penn Su

right now even after restart I still couldn't connect to actions from IB :(

Jarred Sumner

Forget about Xcode integration and/or work on integrating with AppCode from JetBrains (http://www.jetbrains.com/objc/).

What if instead there was an external tool similar to Interface Builder, but specifically for MacRuby? And, this tool would have an API so that other IDE's/text editors can be compatible with it. This would let anyone use their IDE/text editor of choice, without having to write their views in code.

Joshua Ballanco
Owner

It's funny, but what you're describing @Jarred-Sumner is essentially what Interface Builder was way back when Xcode was still Project Builder. It's not a completely crazy idea, especially when you consider that the way Interface Builder works is to simply instantiate and modify objects on the fly (i.e. when you drag an NSButton from the pallet into your app's window, IB is actually doing [[NSButton alloc] init...]), and then persist the resulting object graph to disk.

Personally, I don't have time at the moment to undertake such a project...but if you wanted to start something, I don't think you'd find a lack of interest or support. ;-)

Mark Villacampa

Another possible solution could be the approach that MonoTouch has to this problem: auto generate .h files and populate them with it's correspondent .rb files' attr_accessors and methods with the 'sender' parameter. This way we would be protected against future changes.

The downside could be performance (having to generate .h on each file save) and uglyness (at the end, headers is one of the things we try to avoid with MacRuby)

Are there any other projects using rb_nibtool's process of linking against IB? Is that process explained somewhere?

Mark Rada
Owner

I am not having any issues with outlets and actions. I'm using 10.8.2 with Xcode 4.5 DP2

Mark Villacampa
Watson
Owner

@ferrous26 Thanks! I'm looking forward to Xcode 4.5 :)

Mark Rada
Owner
Mark Villacampa

This is pretty weird. Ive tried several verions of XCode with different results:

Not working: 4.4, 4.4.1, 4.5 DP3, 4.5 DP2
Working: 4.5 DP4

And of course 4.5 DP 4 was released after the other DPs and 4.4, and just one day before 4.4.1

@ferrous26 can you confirm you're using DP2 and not DP4?

Mark Rada
Owner
Penn Su

Does it mean that this issue will be solved in 4.5? But then is it possible to have a simple tweak to make it work for 4.4.x?

Mark Rada
Owner

No changes have been made to the MacRuby side of Xcode integration for quite some time (years). It seems to have been something on the Xcode side of things that changed, and it looks like Apple has fixed it in 4.5. I wouldn't expect them to backport the fix 4.4.x, but you never know what will happen if you open a radar ticket with Apple.

Mark Villacampa

In my opinion, the best we can do is wait until XCode 4.5 is released (probably in a month or so) and see if MacRuby integration is still OK. If yeah, I wouldn't bother trying to get 4.4.X fixed. If it doesn't work, then we have to take action.

As I commented before, IMHO the best approach would be generating .h on the fly on file save, using Ripper and a file watcher, like (for example) @alloy's Kicker (https://github.com/alloy/kicker)

There are several benefits with that:

1- Better integration with obj-c projects
2- Easier to create MacRuby .framework/.a/.dlyb
3- Integration with ANY text editor :)

I would try to get time to work on this (in case it is finally necessary) but I'd need some help from any 'senior' figure in the MacRuby community :P

Murphy Randle

Sorry, I'm a total beginner with Ruby, coming from C++, Python, and QT. I'm trying to follow the basic intro tutorial. Until XCode 5 comes out, is there a way for me to connect the button press event from interface builder to my ruby method "by hand"?

Jim Getzen

To set a target and action programmatically, try this:

my_button.setTarget(my_controller) # or self or whatever should receive the action message
my_button.setAction("button_pressed:") # or whatever method you'd like to call

Then, in my_controller:

def button_pressed(sender)
  #
end
Murphy Randle

Thank you getzen. I'm assuming that I'll need to have created my user interface programmatically versus creating it in the Interface Builder in order to have access to the button's methods. Correct?

Jim Getzen

Not necessarily. The Interface Builder portion of Xcode will scan your source files the each time your project is loaded (at least, this is the behavior I've observed). So, if you add some accessors for buttons and whatnot in your source code and they don't show in IB, close your project and re-open it. That should cause IB to rescan your source files and identify the accessors, or methods in the case of action selectors. Works for me at least.

Murphy Randle

Thanks, getzen. I don't think that my .rb files are getting scanned by xcode at all. Even after restarting I don't have see any accessors after right-clicking on an object to view its attributes.

This is the same behavior that others in this thread are viewing if I'm not mistaken. I'm running XCode 4.4 on Mountain Lion.

Wish I could shell out the $100 to be a real developer :) and get XCode 4.5. The word on the street is that it will be out in a month? Maybe I'll just have to sit tight until then.

Brady Love

I was having this issue as well. Just updated to XCode 4.5 GM, re installed MacRuby (latest nightly) and wen through the steps on this page http://lldong.github.com/blog/2012/03/05/xcode-4-dot-3-macruby-compatible-problem-workaround/ and everything seems to be working as it should.

Penn Su

Yes, also confirmed after updating XCode to 4.5 and reinstalled macruby, now the outlets connections in Interface Builder works immediately.

Mark Rada
Owner

Ok, looks like things are working for everyone again.

Mark Rada ferrous26 closed this
Jarred Sumner

After following this guide, it isn't working for me.

I'm running Mountain Lion 10.8.2 and Xcode 4.5 GM.

The project templates work just fine. Interface Builder, however, doesn't create actions or outlets, or even seem to be aware of Ruby classes.

I've installed MacRuby from the latest nightly build, which was downloaded from here. I symlinked rb_nibtool, as described in the guide, to /Applications/Xcode.app/Contents/Developer/Tools. Then, I restarted Xcode and Interface Builder still didn't let me connect outlets or actions.

What am I doing wrong?

Mark Rada
Owner

@Jarred-Sumner I'm trying to reproduce this issue but everything seems to be working fine for me.

What version of MacRuby are you using? If you are using a nightly build, try running the following command while Xcode is not running:

sudo macruby_install_xcode_support
Joe Fiorini

I think I'm having issues with this as well on Xcode 4.5. Before upgrading to the latest nightly (I was running on 0.12 release) it took all kinds of fiddling to get my outlets/actions to show up in IB, usually some combination of quitting Xcode, changing owner classes and closing/reopening the nib file. A couple times I saw Xcode say it was analyzing my files, and after that the outlets I was waiting for appeared. I'm not sure how to trigger that though, I don't think it's the standard analyze target.

I've upgraded to the last night's build, run macruby_install_xcode_support, tried the steps at http://lldong.github.com/blog/2012/03/05/xcode-4-dot-3-macruby-compatible-problem-workaround/ (this isn't necessary, right? it was already setup for me). Now I cannot seem to get my outlets to show up at all. I ran rb_nibtool manually against the owner class and got this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>IBClasses</key>
    <array>
        <dict>
            <key>ACTIONS</key>
            <array>
                <string>showCreateSiteView</string>
                <string>showChooseSiteToEditView</string>
            </array>
            <key>CLASS</key>
            <string>MainWindowController</string>
            <key>LANGUAGE</key>
            <string>Ruby</string>
            <key>OUTLETS</key>
            <array/>
            <key>SUPERCLASS</key>
            <string>NSWindowController</string>
        </dict>
    </array>
</dict>
</plist>

It looks like it's finding my actions, so my guess is IB isn't running rb_nibtool at all. I'm at a loss for debugging this; does anyone else have any thoughts?

This is the owner class:

class MainWindowController < NSWindowController
    attr_reader :slidingWindowController, :slidingWindow

    def init
        super.initWithWindowNibName "MainWindow"
    end

    def windowDidLoad
         # initialization
    end

    def action1(sender)
    end

    def action2(sender)
    end

end

Perhaps a related note: that this class inherits from NSWindowController. I had originally created my own attr_accessor :window, but removed it because that was overriding NSWindowController's window and causing problems. Now IB is showing a warning that this class doesn't have an outlet named window, but it should be getting it from it's parent, right?

Joe Fiorini

So it appears even though I ran sudo macruby_install_xcode_support I didn't actually have the rb_nibtool symlink in /Applications/Xcode.app/Contents/Developer/Tools. It cat'ed out the script and found a suspicious line near the end:

NSLog("Installing XCode templates")
TEMPLATE_SRC  = "#{FRAMEWORK}/Resources/Templates"
TEMPLATE_DEST = "/Library/Developer/Xcode/Templates/MacRuby"

if File.exist?(TEMPLATE_DEST)
  NSLog("Templates already installed, skipping reinstallation")
else
  FileUtils.mkdir_p(File.split(TEMPLATE_DEST).first) # might need to be created
  FileUtils.rm_f(TEMPLATE_DEST)
  # File.exist? will return false if the file is a broken symlink
  FileUtils.rm_f(NIBTOOL_DEST) # <--- SHOULD THIS BE TEMPLATE_DEST?? # so we remove it no matter what
  File.symlink(TEMPLATE_SRC, TEMPLATE_DEST)
end

Is that actually supposed to delete NIBTOOL_DEST or should that be ensuring the templates were removed by deleting TEMPLATE_DEST?

Joe Fiorini

It seems to be working okay now, sorry for the spam on this issue :) I'll open a new issue if I notice anything further.

Mark Rada
Owner

@joefiorini oops, yes, you found a bug in the xcode setup script. Thank you for pointing that out.

Beat

Is there any solution to this yet? same here....

Joe Fiorini
Beat

@joefiorini I've reinstalled Xcode 4.5 with the latest nightly build, still I am not able to see my attributes (defined with attr_accessor) in the outlet list when I connect to app delegate.

I've run sudo macruby_install_xcode_support.

I'm on OSX 10.8. Is there any way to get this back to work while waiting for a fix (lesser version of Xcode / Macruby or patching rb_nibtool)?

Michael Irey

Just downloaded Mac Ruby today used the nightly release. I am on 10.6.8 and Xcode 4.2. I am also unable to connect to Actions or Outlets. Tried to follow the tutorial https://github.com/MacRuby/MacRuby/wiki/Creating-a-simple-application and gave up.

Is this is still an issue?

Murphy Randle

@michaelirey Upgrading to XCode 4.5 fixed it for me with the nightly build of Macruby.
Have you tried that?

Michael Irey

@murphyrandle I am using Snow Leopard, so the latest Xcode version available is 4.2

Murphy Randle
Joe Fiorini

I often need to restart Xcode or make some arbitrary change to my NIB file to force Xcode into rescanning classes. Once it finishes Scanning Classes (which can take a long time) I always have my outlets. As another approach, I've decided to switch back to Objective C for all of my UI code (mostly controllers) so that I can get the benefits of action/outlet creation by dragging from Interface Builder to my code file. It's made the UI process much easier and smoother.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.