LoginSignup
22
22

More than 5 years have passed since last update.

RubyMotion 事始め

Last updated at Posted at 2013-06-03

RubyMotionとは

  • RubyでiOS, OS Xネイティブアプリを作る toolchain
  • Cocoaフレームワークの上に薄いラッパをかけてRubyから使えるようにしている、よってRubyでCocoaフレームワークを使うというコーディングになる
  • RubyMotionのコンパイラがRubyファイルをアセンブラにし、gccでobjファイルにする、そのためObjective-Cの実装と双方向でやり取りできる
    • Objective-Cの資産も活かせる
  • ネイティブにリンクされるので実行時にJitでコンパイルする他のこの手のものと比べて実行速度が速い
  • エディタは好きなものを選ぶ
  • gemはRubyMotion用のgemしか使えない、RubyMotion Wrappersに有名なものがある
  • motion-cocoapodsを使えばCocoaPodsの実装も簡単に呼び出せる

ライセンス

  • 有償, RubyMotionのサイトから購入可能
    • 試してだめったら30日クーリングオフ可能
  • 購入したバージョンについては有効期限はない
  • 一年間はアップデートを無料で受け取れ、サポートがある
  • 一年後からライセンスの半額で更新すると最新版のアップデートやサポートの権利を得られる

開発に必要なもの

  • OS X 10.6 以上 (10.7以上推奨)
  • RubyMotion
    • ライセンスを買うとインストーラがダウンロードでき /usr/bin/motion にインストールされる
  • Xcode (IDE本体というより以下をインストールするために必要)
    • iOS SDK や OS X SDK
    • Xcode Command Line Tools
  • お好きなエディタ

motionコマンド

$ motion -v
2.0
$ motion --help
Usage:
  motion [-h, --help]
  motion [-v, --version]
  motion <command> [<args...>]

Commands:
  account      Access the software license account
  activate     Activate the software license
  create       Create a new project
  ri           Display API reference
  support      Create a support ticket
  update       Update the software

なんとなくmotion createmotion updateしか使わない予感。

motion create --helpってやったら--helpってプロジェクト作られたので注意。

Hello, World

なんとなくシミュレータ不要なOS Xの方が試すのは楽かなと思ってOS Xでやってみる。

motion createでプロジェクト作成。

motion create --template=osx Hello

こんな感じの階層。

rubymotion_2013-05-31_1743.png

チュートリアルに沿って app/app_delegate.rb にAlertを追加してみる。

app_delegate.rb
class AppDelegate
  def applicationDidFinishLaunching(notification)
    buildMenu
    buildWindow

    # 追加
    alert = NSAlert.new
    alert.messageText = 'こんにちは'
    alert.runModal
  end

  def buildWindow
    @mainWindow = NSWindow.alloc.initWithContentRect([[240, 180], [480, 360]],
                                                     styleMask: NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask,
                                                     backing: NSBackingStoreBuffered,
                                                     defer: false)
    @mainWindow.title = NSBundle.mainBundle.infoDictionary['CFBundleName']
    @mainWindow.orderFrontRegardless
  end
end

rakeで実行。

rubymotion_2013-05-31_1744.png

これは便利だ。あとはサンプルプロジェクトを見ながら勉強していく。
https://github.com/HipByte/RubyMotionSamples

22
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
22