Installation

Installation might take a few steps, but it's easy with RubyMotion. The most complicated part is that you're not told what editor to use. Read this section and spend some genuine time finding the right groove for your development. Once you've found an editor or IDE you're comfortable with, you'll be able to focus on your apps.

The process to get RubyMotion in place may seem time-consuming, but it's relatively simple. In this section, you'll get cozy with RubyMotion and the necessary tools installed, plus you'll get the editor of your choice by your side, so you can eventually write your first application!

Basic installation

Some flavors of Ruby can be a real headache to install depending on the system, but, fortunately, installing RubyMotion is simple. To get started with your installation of RubyMotion, you'll need a Mac running OS X 10.6 or higher.

Step 1 – installing the iOS SDK

To get the iOS software development kit (SDK), you'll need to grab Xcode from the Mac App Store. This should be second nature for most Mac users, but we'll go through the steps just in case you are completely unfamiliar with this process.

  1. Pull up App Store from your Applications folder (usually in the Dock) or type "App Store" in Spotlight to load your App Store applications.
  2. Once the App Store is loaded, search for "Xcode" in the search box at the top-right corner and the first result should be the Xcode Developer Tools.
  3. Download and install this to get the iOS SDK on your local machine.

    The icon and install will look like this:

    Step 1 – installing the iOS SDK

Tip

This often takes a good bit of time if it's your first pull-down of Xcode, so snacking and continuing to read this book is highly encouraged!

Note

Xcode is Apple's IDE for application development. You're not very likely to be using any of the IDE benefits in RubyMotion, we simply need the SDK and command-line tools.

Finally, at some point Xcode will finish downloading and installing. We're almost done with Xcode now, but we need Command Line Tools (so RubyMotion can perform its magic). We need to perform the following steps to install Command Line Tools:

  1. Open Xcode (using Spotlight or your preferred method) and click on Preferences.
  2. The window that appears will have a Downloads tab you will need to click. You'll see a package called Command Line Tools with an Install button to the right. You guessed it right! You'll need to click on Install for this tool to download:
    Step 1 – installing the iOS SDK

Now that you've downloaded everything you can close it all. You have all the tools you'll need from Apple.

It is important to keep Xcode and Command Line Tools up-to-date since this is how we will access features of the latest Apple SDK.

Note

If you have downloaded an older version of Xcode (Pre-App Store), or you're fancy and you're looking to use a beta of the next Xcode before it is available in the App Store, you can change versions of Xcode at the command line using xcode-select:

$ sudo xcode-select –switch /Path/To/Xcode.app/Contents/Developer

You can use this command to switch between multiple versions of Xcode, but this is generally uncommon in basic development.

Step 2 – RubyMotion buy/install/update

That's right, it's time to buy! At the time of writing, there's a nice large Buy menu item on RubyMotion.com that brings you to their purchasing address (http://sites.fastspring.com/hipbyte/product/rubymotion).

Once you've gone through the standard purchasing process, HipByte will send you a purchase license key and an installer application. Install the application like any other Mac application install and you're ready to hit the ground running.

To activate your RubyMotion application you'll use the activate command. Get your activation key ready and load up a terminal window. You'll need to type the following, and then follow the instructions presented to you to activate your copy of RubyMotion:

$ sudo motion activate

Activation is a one-time-per-machine task. It's probably a good idea to update your download of motion before we get started. To run a quick update, you keep open that same terminal and type the following command:

$ sudo motion update

You don't have to guess when updates are released. RubyMotion will often prompt you to run the preceding command if it notices your local version is not equal to the latest stable release.

You now have motion installed and you're ready to start writing apps! The following two sections are about where you write those apps.

Editor independence

Following in the footsteps of most Ruby development, you're not constrained to a particular editor and especially not to a particular IDE. This means you can write code in any text application! Obviously, you'll want some benefits, such as code formatting, completion, coloring, and so on, but you're not limited to the editors described.

If you haven't already fallen in love with an editor, the following is a Ruby / RubyMotion developer's guide to some popular and documented editors, so you can make a choice that suits you.

The editors are listed in the following list in alphabetical order:

  • Emacs (free) – This editor from the 1970s is well rooted in the development community. To get Emacs to understand RubyMotion code, you'll need to generate ctags that Emacs can understand. Adding -e to the file located at /Library/RubyMotion/data/bridgesupport-ctags.cfg will change your rake ctags command to generate the tags file readable by Emacs. There's nothing Ruby proficient about this editor other than its stability and cost.
  • Redcar (free) – If you are a fan of open source projects, you might consider using Redcar. This editor was even written in Ruby! There is a redcar-rubymotion plugin to help you get your RubyMotion integration.
  • Sublime Text (USD 70) – One of the newest and biggest movers/shakers to hit the text editing market is Sublime Text (currently often called Sublime Text 2 or Sublime Text 3, depending on the version). This editor is usually coupled with a package manager that allows you to easily find, install, upgrade, and remove packages in Sublime. Once you have installed the package manager, you can install the SublimeRubyMotionBuilder plugin.
  • TextMate (~USD 52) – A popular OS X based editor that probably needs no introduction. Created by Unix geeks this editor is still chugging away and consumes a large portion of editors of choice.
  • Vim (free) – Based on the age old vi editor, Vim is lightweight, highly configurable, terminal-based, and dynamic. Vim is usually a jump into the deep end of editors, and not for the faint of heart. Ultimately, it is considered the "Programmer's Editor" and usually holds high regard in most code camps.

I personally develop in either Vim or Sublime Text, depending on the operating system of the machine I'm using. Both are amazing with RubyMotion and easily take care of my development needs.

RubyMine and IDEs

IDEs generally give you all the benefits of the normal text editors, but they'll usually hold your hand through additional characteristics such as source control, test run integration, autocompletion, refactoring tools, alerts, help notifications, and debugging. Though you can become highly dependent on an IDE, it can really help and guide you through your venture into a new programming experience. If you're looking to diminish the abruptness of any learning curve, an IDE is generally a good way to go.

If Ruby is old hat for you, you're probably familiar with, or have at least heard of, RubyMine. RubyMine is the most intelligent Ruby development tool I've come across. It's a full-fledged IDE that can handle your Ruby on Rails projects, as well as your RubyMotion development.

If you haven't already, give RubyMine a try. They have a free 30-day trial you can grab from http://www.jetbrains.com/ruby/.

The following screenshot shows the JetBrains installer:

RubyMine and IDEs

Once you've downloaded RubyMine's DMG, you do the usual drag to the Application folder, and, on the first run of the application, choose the Evaluate for free for 30 days option.

As previously mentioned, IDEs give you a lot of hand holding, which is great if you're new to either Git or the iOS framework methods/objects. RubyMine is no exception, with tightly integrated support on the wide array of tools used in RubyMotion. The Breakpoints and Rerun Simulator button are amazing for those small changes you need to get just right.

To view the IDE in action, check out this screencast:

http://tv.jetbrains.net/videocontent/rubymotion-support

Customizing RubyMine

If you're anything like me, the first thing you'll want to do is get rid of that bright background before it burns your eyes out. My favorite scheme is RailsCasts (Preferences | Editor | Colors & Fonts). Obviously, the IDE supports color schemes for all.

Additionally, if you come from the Vim world, there's a plugin called IdeaVim (Sublime Text has something similar) that allows you to apply all your wonderful Vim shortcuts inside the editor. Go to Preferences | Plugins | Install plugin to install the plugin from the disk (http://plugins.jetbrains.com/plugin/?id=164).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset