Search code examples
rubymotion

RubyMotion: How do I call a function in the console?


I have two controllers - how can I call the functions in them from the console?

(main)>


Solution

  • The only way I can figure out how to do this is by using the UIApplication sharedApplication class method and drilling down from there, which is pretty icky.

    (main)> UIApplication.sharedApplication.delegate
    => #<AppDelegate:0x6c8a800 @window=#<UIWindow:0x6e71280>>
    

    Unfortunately to access the window I had to add an attr_reader :window to my AppDelegate class to access this private variable and then drill down even further to get at the view controllers:

    (main)> vc = UIApplication.sharedApplication.delegate.window.rootViewController
    => #<TouchesViewController:0x8c747c0>
    

    Now you should be able to call any public methods on that view controller.