RubyMotion Blog

Avatar

This is the official blog of RubyMotion, a toolchain for iOS and OS X development that lets do you do iPhone, iPad and Mac apps in Ruby.

Follow us on Twitter to stay tuned with everything that's happening in the community!

Not a RubyMotion user yet? Give it a spin today!

RubyMotion gets iOS 6, iPhone 5, debugger

We are glad to announce that RubyMotion 1.24 is available to all users. This is by far the biggest software update we have done so far, so let’s go through the most important changes.

iOS 6 SDK

This release adds support for the iOS 6 SDK.

Unlike some other mobile development platforms, RubyMotion is a pure native toolchain that can automatically support new SDKs, just like Apple’s Objective-C. Therefore, RubyMotion already supported the iOS 6 SDK the same day it was announced at WWDC 2012.

However, the support for iOS 6 wasn’t shipping as part of RubyMotion for legal reasons, as it was still under NDA. Until yesterday!

To program with the iOS 6 SDK you will need to download and install Xcode 4.5 from Apple’s developer center. There you will also find exhaustive documentation about the new frameworks and APIs of iOS 6. UICollectionView, a new UIKit class that can be used to easily create view layouts, is brand new in iOS 6. We could not resist porting one of the WWDC samples to RubyMotion: CircleLayout.

iPhone 5

You probably heard about the new iPhone 5 which was announced last week!

The iPhone 5 features a 4-inch retina display. The RubyMotion build system was improved so that you can specify the retina resolution the simulator should use, by providing different values for the retina option.

$ rake retina=4   # starts the 4-inch simulator (iPhone 5)
$ rake retina=3.5 # starts the 3.5-inch simulator (iPhone 4S and older)

If a true value is provided for the retina option, the build system will default to 4-inch in case the simulator target is 6.0, otherwise 3.5-inch.

On the technical side, the new iPhone 5 has a new processor architecture called armv7s. The RubyMotion compiler now supports this new architecture. Applications built for iOS 6 will contain code for both armv7 (iPhone 4S and older) and armv7s.

Debugger

This has been one of the most requested feature. As of 1.24, RubyMotion comes with debugging facilities based on GDB, the GNU project debugger. The RubyMotion compiler has also been improved to statically emit the appropriate DWARF debugging metadata for the Ruby language. 

The debugger lets you set source-level breakpoints, inspect contextual variables, backtrace frames, threads, and control the execution flow.

Debugging is supported on both the simulator and the device. You can start the debugger by setting the debug option to the appropriate rake tasks.

$ rake simulator debug=1
$ rake device debug=1

In the simulator target the debugger will replace the read-eval-print-loop interactive console. In the device target you will notice that the debugger will start right after the application has been installed and run the application. This is already a significant improvement over previous RubyMotion releases as you will see the application logs in your terminal window. 

$ rake device debug=1
(in /Users/lrz/src/RubyMotionSamples/Hello)
     Build ./build/iPhoneOS-6.0-Development
    Deploy ./build/iPhoneOS-6.0-Development/Hello.ipa
Switching to remote-macosx protocol
[...]
^C
Program received signal SIGSTOP, Stopped (signal).
0x3304eeb4 in mach_msg_trap ()
(gdb) break hello_view.rb:10
Breakpoint 1 at 0x26d84: file hello_view.rb, line 10.
(gdb) c
Continuing.

Breakpoint 1, rb_scope__drawRect:__ (self=0x208495f0, rect=0x20851260)
    at hello_view.rb:10
10            bgcolor = UIColor.blackColor
Current language:  auto; currently minimal
(gdb) pro self
#<HelloView:0x208495f0>
(gdb) pro rect
#<CGRect origin=#<CGPoint x=0.0 y=0.0> size=#<CGSize width=320.0 height=480.0>>
(gdb) n
14          bgcolor.set
(gdb) n
15          UIBezierPath.bezierPathWithRect(frame).fill
(gdb) n
17          font = UIFont.systemFontOfSize(24)
(gdb) n
18          UIColor.whiteColor.set
(gdb) pro font
#<UICFFont:0x2084c040>
(gdb) n
19          text.drawAtPoint(CGPoint.new(10, 20), withFont:font)
(gdb) pro text
"Touched 1 times!"
(gdb) c
Continuing.

To know more about the new debugger check out the new Debugging RubyMotion Applications article in our developer center.

The debugger is at this time quite rudimentary and will be significantly improved in the next updates. We also understand that GDB is not for everyone. We are however very excited about this new debugging facility and we see it as a first step towards a higher-level, friendlier debugger that will eventually be integrated into the existing read-eval-print-loop interactive console. 

Misc

Module#define_method is now implemented as of RubyMotion 1.24. This method lets you dynamically define a new method and is often used in DSLs / meta-programming. Please note that, because of technical limitations of the static compiler, it is not possible yet to use #define_method to overwrite an existing Objective-C-level method.

The libdispatch’s dispatch_once() function is now exposed via the new Dispatch.once method. This method accepts a block that is guaranteed to be yielded exactly once in a thread-safe manner. dispatch_once() is often used in Objective-C programs to create thread-safe singleton objects and the same can be done in RubyMotion apps now.

class MyClass
  def self.instance
    Dispatch.once { @instance ||= new }
    @instance
  end
end

Last but not least, this update brings performance improvements in the String class and fixes several bugs in the other builtin classes. 


Interested in giving RubyMotion a try? We offer a 30 days money back guarantee. Download it today!
Follow us on Twitter to stay tuned with everything that is happening in the community.

By Laurent Sansonetti.