LoginSignup
2
2

More than 3 years have passed since last update.

RubyMotionを使ってみる

Posted at

RubyMotionを使ってみる。すでに、以下のcocoaというgemを使っているが、うまく動かないケースがあり、まずは他のプラットフォームも使ってみようという意図。
https://github.com/patrickhno/cocoa/

RubyMotionの登場は、2012年5月。
https://el.jibun.atmarkit.co.jp/rails/2012/05/macrubyiosrubym-7bc3.html

RubyMotionの後継として、DagonRubyが登場しており、RubyMotion自体はディスコンが決まっている。
http://www.rubymotion.com/news/2019/04/19/plans-for-rubymotion.html
http://www.rubymotion.com/news/2020/01/02/year-end-review.html
https://dragonruby.itch.io/
こちらは、SDLの後継のようだ。Cocoaの機能を使いたいという意図で使うものでは無い。マルチプラットフォームのゲーム開発に使う。

ただ、RubyMotionのversion upは続けられており、version 7.6では、macOS Catalina(10.16.6)、Xcode 11.6、Swift 5への対応は行われている。

RubyMotion

RubyMotionを使ってみる。

% motion --version
7.5
% sudo motion update

= RubyMotion 7.6 =

  * [Xcode] Added support for Xcode 11.6.

  * [Bugfix] `Pointer.new` top level retain behavior has been reverted. If you were having crashes
    in RM 7.5, this should resolve that issue. The retain logic for Pointer has instead
    been scoped down to the access of the value. If you want the Pointer to auto release, instead of:

    ```
    @pointer = Pointer.new(:object)
    someObjectiveCFunction(@pointer)

    .... later in code ....

    puts @pointer.value
    ```
    You will need to do:

    ```
    pointer = Pointer.new(:object)
    someObjectiveCFunction(pointer)
    @pointer_value = pointer.value_with_autorelease

    .... later in code ....

    puts @pointer_value
    ```

    If the value within the Pointer is an array. Instead of:
    ```
    @pointer = Pointer.new(:object)
    someObjectiveCFunction(@pointer)

    .... later in code ....

    puts @pointer[0] # alias is @pointer.value_at(0)
    puts @pointer[1] # alias is @pointer.value_at(1)
    ```

    You will need to do

    ```

    If the value within the Pointer is an array. Instead of:
    ```
    pointer = Pointer.new(:object)
    someObjectiveCFunction(@pointer)
    @pointer_item_1 = pointer.value_at_with_autorelease(0)
    @pointer_item_2 = pointer.value_at_with_autorelease(1)

    .... later in code ....

    puts @pointer_item_1
    puts @pointer_item_2
    ```

  * [Xcode Beta] Added support for Xcode 12.0 running on macOS Catalina. This is only
    for Indie and Pro subscriptions. Big Sur plus Apple Silicon support will be released
    at a future date. Come to the Slack channel for updates: http://slack.rubymotion.com.

(Run `motion changelog` to view all changes.)
==========================================================================================
WARNING: Additional commands need to be downloaded. Please run: `motion repo`.
==========================================================================================
% motion --version
7.6

使ってみる。

% cd ~/dev
% motion create --template=osx Hello
[!] You may want to run `motion repo` if it's been a while since you've updated templates.
    Create Hello
    Create Hello/.gitignore
    Create Hello/Gemfile
    Create Hello/README.md
    Create Hello/Rakefile
    Create Hello/app/app_delegate.rb
    Create Hello/app/menu.rb
    Create Hello/resources/Assets.xcassets/AppIcon.appiconset/1024x1024.png
    Create Hello/resources/Assets.xcassets/AppIcon.appiconset/Contents.json
    Create Hello/resources/Assets.xcassets/AppIcon.appiconset/Icon_128x128.png
    Create Hello/resources/Assets.xcassets/AppIcon.appiconset/Icon_128x128@2x.png
    Create Hello/resources/Assets.xcassets/AppIcon.appiconset/Icon_16x16.png
    Create Hello/resources/Assets.xcassets/AppIcon.appiconset/Icon_16x16@2x.png
    Create Hello/resources/Assets.xcassets/AppIcon.appiconset/Icon_256x256.png
    Create Hello/resources/Assets.xcassets/AppIcon.appiconset/Icon_256x256@2x.png
    Create Hello/resources/Assets.xcassets/AppIcon.appiconset/Icon_32x32.png
    Create Hello/resources/Assets.xcassets/AppIcon.appiconset/Icon_32x32@2x.png
    Create Hello/resources/Assets.xcassets/AppIcon.appiconset/Icon_512x512.png
    Create Hello/resources/Assets.xcassets/AppIcon.appiconset/Icon_512x512@2x.png
    Create Hello/resources/Assets.xcassets/Contents.json
    Create Hello/resources/Credits.rtf
    Create Hello/spec/main_spec.rb
% cd Hello
% sudo cp -r /usr/lib/swift/*.dylib /Applications/Xcode.app/Contents/Frameworks/
% sudo touch /Applications/Xcode.app/Contents/Frameworks/.swift-5-staged
% setenv OBJC_DISABLE_INITIALIZE_FORK_SAFETY YES
% rake
Resolving dependencies...
    ERROR! Deployment target 10.13 is not supported by this version of RubyMotion. If you are using the Starter Version, make sure you are running the latest version of XCode, and both `app.deployment_target` and `app.sdk_version` are commented out in the Rakefile. If you are updating to a new version of RubyMotion or Xcode, be sure to open Xcode at least once, run `sudo xcode-select --reset`, and then `rake clean:all default`. If you need more help, come to the Slack Channel: http://motioneers.herokuapp.com.
  • Rakefileのapp.deployment_targetをコメントアウトする。
Rakefile
Motion::Project::App.setup do |app|
  # Use `rake config' to see complete project settings.
  app.name = 'Hello'
  #app.deployment_target = '10.13'
  app.info_plist['CFBundleIconName'] = 'AppIcon'
end
% rake
     Build ./build/MacOSX-10.15-Development
   Compile ./app/app_delegate.rb
   Compile ./app/menu.rb
    Create ./build/MacOSX-10.15-Development/Hello.app/Contents
    Create ./build/MacOSX-10.15-Development/Hello.app/Contents/MacOS
      Link ./build/MacOSX-10.15-Development/Hello.app/Contents/MacOS/Hello
    Create ./build/MacOSX-10.15-Development/Hello.app/Contents/PkgInfo
   Compile ./resources/Assets.xcassets
    Create ./build/MacOSX-10.15-Development/Hello.app/Contents/Info.plist
      Copy ./resources/Credits.rtf
    Create ./build/MacOSX-10.15-Development/Hello.app.dSYM
      Copy ./build/MacOSX-10.15-Development/Hello.app.dSYM
       Run ./build/MacOSX-10.15-Development/Hello.app/Contents/MacOS/Hello
(main)> exit
Remote process has quit.
  • 黒い画面が出た。

done!

2
2
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
2
2