News

 
  • 04 Mar

    New in RubyMotion: New CLI, WeakRef Zeroing, Background Fetch Testing, Subscripting, Performance

    We shipped quite a few releases since the beginning of the year. Let’s dig into the new major features.

    New Command-Line Interface

    The motion command-line interface has been fully rewritten using the CLAide project.

    $ motion 
    RubyMotion lets you develop native iOS and OS X applications using the awesome Ruby language.
    
    Commands:
    
        * account          Access account details.
        * activate         Activate software license.
        * changelog        View the changelog.
        * create           Create a new project.
        * device-console   Print iOS device logs
        * ri               Display API reference.
        * support          Create a support ticket.
        * update           Update the software.
    
    Options:
    
        --version   Show the version of RubyMotion
        --no-ansi   Show output without ANSI codes
        --verbose   Show more debugging information
        --help      Show help banner of specified command
    

    The new codebase allows better output and more elaborated argument handling. It will also allow us to extend the interface more easily in the future.

    WeakRef Zeroing

    In previous builds, trying to send a message to a WeakRef object whose internal reference was prematurely destroyed was causing a crash at runtime, since it was attempting to send a message to an invalid object address.

    Now, the internal reference of WeakRef objects will properly be zeroed when it is destroyed. Sending a WeakRef object a message whose internal reference has been zeroed will cause a WeakRefError exception at runtime, matching exactly the behavior of CRuby’s weakref.rb standard library.

    The WeakRef#weakref_alive? method was also added and will return false in case the internal reference has been zeroed.

    autorelease_pool do
      @ref = WeakRef.new(Object.new)
    end
    @ref.weakref_alive? #=> false
    @ref.description    #=> WeakRefError: Invalid Reference - probably recycled
    

    Background Fetch Testing

    iOS 7 introduced the notion of background fetch which for example allows your application to check a remote web API if there is any updated content and, if so, fetch it, all while being in a suspended state.

    To perform a background fetch iOS will launch your application using the application:performFetchWithCompletionHandler: method. You can now simulate this on the iOS Simulator by setting the background_fetch environment variable, as show below.

    $ rake background_fetch=1
    

    Note that while your application is in the background you will not be able to REPL until you activate the application again.

    Object Subscripting

    As of clang 3.1 Objective-C developers are able to add support for the new Objective-C literal syntax on their own classes by implementing a set of methods.

    RubyMotion will now properly handle objects from these classes and allow you to send the #[] and #[]= messages on them as convenience shortcuts.

    As an example, let’s take a fictional SubscriptingExample Objective-C class:

    @implementation SubscriptingExample
    
    - (id)objectAtIndexedSubscript:(NSUInteger)index;
    {
      ...
    }
    
    - (void)setObject:(id)object atIndexedSubscript:(NSUInteger)index;
    {
      ...
    }
    
    - (id)objectForKeyedSubscript:(id)key;
    {
      ...
    }
    
    - (void)setObject:(id)object forKeyedSubscript:(id)key;
    {
      ...
    }
    
    @end
    

    The following class can now be used from Ruby code using convenience shortcuts.

    obj = SubscriptingExample.new
    obj['one'] = 1
    puts obj['one']
    ...
    

    Performance Improvements

    As you could see from the release notes our goal of improving the overall performance of RubyMotion apps is continuing steadily.

    Runtime primitives (such as the method dispatcher) are faster by 25%. Builtin classes methods have also been optimized, sometimes by a 2x factor. Some of our users reported very positive feedback from their testers.

    As mentioned in our previous report, we are still working on a benchmark suite for RubyMotion. Its goal is to let us identify performance problems as well as catching performance regressions. It is still at this time a work in progress and we still intend to publish it once it’s complete.

    Jim Weirich

    Jim was one of the very early RubyMotion users. He believed in the project and gave us the motivation we needed to keep working on it and launch it.

    As the author of Rake, it goes without saying that RubyMotion would not exist without him.

    You can watch Jim speaking about RubyMotion at the local Cincinnati Cocoa user group. In this video, Jim demonstrates his legendary joie de vivre as well as his excellent teaching skills.

    You can also check out Jim teaching the use of source code control (you do use SCC on your RubyMotion apps, right?) for the Pragmatic Programmers, who have kindly agreed to donate the full proceeds of the screencast to Jim’s family.

    Jim passed away the 19th February 2014. He will be deeply missed. Rest in peace, Jim.

 
 

Want to stay in touch?

Follow us on Twitter