Apex is an example of why RubyMotion is awesome

I was working on a very peculiar OS X application, which needed to communicate with an iPad app over the local network. There are a variety ways of doing an RPC (remote procedure call) from low level TCP/IP on up to something silly like SOAP.

I decided to try Apex from our favorite ProMotion author Jamon Holmgren. It would allow me to have a little web server in my OS X app that could serve JSON to my iPad app via rest calls.

That may sound a bit silly, but this app was local only with no Internet connection and as it’s going to run on a Mac Pro, so performance doesn’t matter.

It actually worked really well and was super trivial to use. However, I did have to add a few features to Apex first: JSON support and the ability to create a website in something other than the app delegate. Here is an example, you adding a web server to your app:

Add to gemfile:

gem 'apex', :git => 'https://github.com/clearsightstudio/apex.git'

Create this class:

class WebServer < Apex::Server
  port 8080

  get "/foo", response_type: :json do |request|
    result = SomeClass.some_method
    {success: result}
  end
end

Simple as that. In the iPad app I just used AFMotion to call the API I created in minutes. Pretty neat.


If you missed the last issue, you can find it here: issue #34.

Happy coding, Todd Werth (@twerth)

Articles, News, New Gems, and Blog Posts


July 29th, 2014 | meetup | by utwang
Yokohama City, Japan – Study session in Yokohama Mokumoku 1st RubyMotion

July 16th, 2014 | meetup | by NSFargo
Fargo, ND, USA – NSFargo Meetup

July 9th, 2014 | blog post | by Jack Watson-Hamblin
Is Swift Production Ready?

July 7th, 2014 | screencast | by Jack Watson-Hamblin
MotionInMotion – Episode 32 – Classes to Procs to Blocks

July 7th, 2014 | new gem | by Gant Laborde
motion-keychain – An easy RubyMotion gem for utilizing secure storage

July 3rd, 2014 | blog post | by Steve Ross
RubyMotion Testing Vacuum

Hidden Gem by Gant Laborde of Iconoclast Labs


Caveat when creating a RubyMotion gem: Most gems have a nice clean example app that comes with them in the /app folder. Some of us depend on this local app to help us iron out the kinks of the gem’s usage and examples. It’s also a great place to write the specs.

My hidden gem for you is a small nugget of information that will help you keep your sanity if you follow the aforementioned paradigm. Special thanks to Mark Rickert who helped me notice this issue before I lost my sanity trying to test the motion-keychain gem.

If you’re working on a gem that depends on a pod, the gem template cannot load the needed pod from the gemspec UGH! So you’ll just have to load a separate project, and point the gem’s :path => '../gem_name_here', OR load pods independent of your gem’s pod dependencies.

As far as I can tell, a pod dependency is the only situation limiting you from handling the whole bundle from utilizing a gemspec.

From the Archives

Because it’s easier to copy and paste than to write


Enable User Interaction

You may have noticed that gestures don’t work on images (such as tap). They actually do, but userInteractionEnabled is false on UIImageViews by default. You simply need to turn on user interactions. The same is true for UILabel.

my_view = UIImageView.alloc.initWithFrame([[100,100],[100,100]])
self.view.addSubview(my_view)
my_view.userInteractionEnabled = true
recognizer = UITapGestureRecognizer.alloc.initWithTarget(self, action: 'some_method')
my_view.addGestureRecognizer(recognizer)

Other types of views, such as UIButtons, default to true, thus why gestures work for them.

If you use RMQ, you can do this:

rmq.append(UIImageView, :style_name).enable_interaction.on(:tap) do |sender|
  # do something
end

One more thing


Whats you’re favorite ruby trick or quirk that most people don’t know about


If you have any tips, blog posts, or want to sponsor this newsletter, please send emails to todd@infinitered.com