We're hiring!

We're actively seeking designers and developers for all three of our locations.

Linking Against libarclite in Ruby Motion

I ran into this runtime error the other day when testing a Ruby Motion app on a device with iOS 5.1 installed:

-[__NSArrayI objectAtIndexedSubscript:]: unrecognized selector sent to instance

Everything had been working fine in iOS 6 and, previously, when testing in iOS 5.x. The change that introduced this issue was upgrading a vendored version of the Objective-C SDWebImage library. In the latest version, the developers started using indexer syntax on NSArray, which allows one to access the contents of an NSArray like this: arr[2] instead of the old syntax: [arr objectAtIndex:2].

As our team was using the iOS 6.0 SDK, compiling this code wasn’t an issue. The root of our problem was that arr[2] is effectively translated into [arr objectAtIndexedSubscript:2] at compile time. The - objectAtIndexedSubscript: method is implemented in iOS 6 on NSArray to behave just like objectAtIndex:. However, as we discovered earlier, it is not implemented in iOS 5.x.

After some digging, I learned that this is usually not an issue when compiling an app with ARC support using the 6.0 SDK due to the inclusion of the libarclite library at link time. This library, among other things, provides a shim implementation of [NSArray objectAtIndexedSubscript:]. By passing the flag -fobjc-arc during the link phase, this library will be included.

Now our problem was Ruby Motion doesn’t currently use the -fobjc-arc flag during linking unless the deployment target is less than 5.0. But, I found a way to sneak a flag into the link phase:

Motion::Project::App.setup do |app|
  app.libs << "-fobjc-arc"

With this in place, we were back up and running on iOS 5.x and 6.0.

p.s. Using rake --trace was very useful for seeing all the commands being run (and verifying the inclusion of -fobjc-arc) thanks to Ruby Motion’s diligent use of the sh helper.

Micah Alles (27 Posts)

I’ve been developing software at Atomic Object since May 2002 – starting as an intern, graduating to full-time employment, and eventually becoming a part owner in 2009. Over the years I’ve lead and been a team member on multiple mobile, web, and desktop projects for clients ranging from startups to the Fortune 500. I love being part of a company with such a strong culture of moving forward and increasing our collective average of skill and quality, in particular, through my favorite two of our five value mantras: Give a Shit, and Teach and Learn.

This entry was posted in Ruby Motion and tagged , . Bookmark the permalink. Both comments and trackbacks are currently closed.


  1. Posted December 10, 2012 at 9:32 am

    Thanks for this post. It’s useful knowledge if I ever run into this issue in the future. Haven’t so far, but I use SDWebImage in a few Objective-C projects so it would make sense if I include it in a RubyMotion project in the future.

    • Keyvan
      Posted December 20, 2012 at 9:55 pm

      Thank you! I’ve been trying to debug this for the past 8 hours or so with Crittercism. I finally googled the error

      [__NSArrayI objectAtIndexedSubscript:]: unrecognized selector sent to instance

      and found this, added the flag and everything is great now!