Book Image

RubyMotion iOS Development Essentials

By : Abhishek Nalwaya, Akshat Paul
Book Image

RubyMotion iOS Development Essentials

By: Abhishek Nalwaya, Akshat Paul

Overview of this book

RubyMotion is a revolutionary toolchain for iOS app development. With RubyMotion, you can quickly develop and test native iOS apps for the iPhone and iPad, combining the expressiveness and simplicity of Ruby with the power of the iOS SDK. "RubyMotion iOS Development Essentials" is a hands-on guide for developing iOS apps using RubyMotion. With RubyMotion, you can eliminate the complexity and confusion associated with the development of iOS applications using Objective-C. We'll begin from scratch. Starting by installing RubyMotion, we'll build ourselves up to developing an app that uses the various device capabilities iOS has to offer. What's more, we'll even learn how to launch your app on the App Store! We'll also learn to use iOS SDK classes to create application views. Discover how to use the camera, geolocation, gestures, and other device capabilities to create engaging, interactive apps. We'll develop stunning user interfaces faster with the XCode interface builder and make web apps by using WebView. We'll then augment applications with RubyMotion gems, doing more by writing less code and learn how to write test cases for RubyMotion projects. Finally, we'll understand the app submission process to push your app to Apple's App Store With "RubyMotion iOS Development Essentials", we will learn how to create iOS apps with ease. At the end of each chapter we will have a tangible and running app, which utilizes the concepts we have learnt in that chapter.
Table of Contents (19 chapters)
RubyMotion iOS Development Essentials
About the Authors
About the Reviewers

Why RubyMotion?

So far we have learned what RubyMotion is, but the question that comes to mind is, why should we use RubyMotion? There are many reasons why RubyMotion is a good choice for building robust iOS apps. The following sections detail a few that we think matter the most.

If you are not an Objective-C fan

For a newbie developer, Objective-C is an arduous affair. It's complicated to code; even for doing a simple thing, we have to write many lines of code. Though it is a powerful language and one of the best object-oriented ones available, it is time consuming and the learning curve is very steep. On the other hand, Ruby is more expressive, simple, and productive in comparison to Objective-C. Because of its simplicity, developers can shift their focus onto problem solving rather than spending time on trivial stuff, which is taken care by Ruby itself. In short, we can say RubyMotion allows us to use the power of Objective-C with the simplicity of Ruby.

Ruby classes used in RubyMotion are inherited from Objective-C classes. If you are familiar with the concept of object-oriented programming, you can understand its power. This means we can directly use Apple iOS SDK classes from your RubyMotion code. We will be discussing more on this in the next chapter.


Ruby classes in RubyMotion have the same ancestor as Objective-C.

It is not a bridge

RubyMotion apps get direct access to iOS SDK APIs, which means the size of application and performance created using RubyMotion is comparable to the one created using Objective-C. It implements Ruby on top of the Objective-C runtime and iOS Foundation classes. RubyMotion uses a state-of-the-art static compiler based on Low Level Virtual Machine (LLVM), which converts the Ruby source code into a blazing fast machine code. The original source code is never present in the application bundle. A typical application weighs less than 1 MB, but the size can increase depending on the use case.

Managed memory

One of the key features of RubyMotion is that it takes care of memory management. Just like ARC (Automatic Reference Counting) with Xcode 4.4 and above, we don't have to take the pain of releasing the memory once an object is no longer used. RubyMotion does the magic and we don't need to think about it. It handles it on its own.

Terminal-based workflow

RubyMotion has a terminal-based workflow; from creation of the application to deployment, everything can be done through terminals. If you are used to working on terminals, you know it adds to speedier development.

Easy debugging with REPL

The terminal window where you run Rake also gives you the option to debug with REPL (Read Evaluate Print Loop), which lets you use Ruby expressions that are evaluated on the spot, and the results are reflected on the simulator while the application is still running. The ability to make live changes to the user interface and internal application data structures at runtime is extremely useful for testing and troubleshooting issues with the application, as this saves a lot of time and is much faster than a traditional edit-compile-run loop. If this confuses you right now, don't worry, as we will discuss more on this powerful feature in later chapters.


REPL is similar to IRB in Ruby.

It is extendable

We can use RubyMotion salted gems easily by just adding them in the Rakefile. What are RubyMotion salted gems? We can't use all the gems that are available for Ruby right now, but there are a lot of gems specifically developed for RubyMotion. As the RubyMotion developer community expands, so will its gem bouquet, and this will make our application development rapid.

Third-party Objective-C libraries can be easily used in a RubyMotion project. It supports CocoaPods, which is a dependency manager for Objective-C libraries, making this process a bit easier.

Debugging and testing

RubyMotion has a console-based inbuilt interactive debugger for troubleshooting the issues both on a simulator and on a device using GDB (GNU Debugger). GDB is extremely powerful on its own, and RubyMotion uses it for debugging the compiled Ruby code. Also, RubyMotion projects are fit for Test Driven Development (TDD). We can write a unit test for our code from the beginning. We can use Behavior Driven Development (BDD) with RubyMotion, which is integrated into every project. We will discuss more about testing in later chapters.


RubyMine editor also supports RubyMotion and it has a very powerful debugging mechanism through breakpoints.