LoginSignup
6
6

More than 5 years have passed since last update.

RubyMotionでObjective-Cのコードをそのまま使う方法

Posted at

RubyMotionでObjective-Cのコードをそのまま使うにはこんな感じでやれば良いらしい。凄い簡単だった。

やることは2つ。
vendor以下にそのまま使いたいObjective-Cのコードを追加。
次にRakefileに以下を記述。

  app.vendor_project("vendor",:static)

これでOKらしい。

というわけで試してみた。
ちなみにvendor直下に入れてrakeをするとエラー。
僕の環境の場合だとvendor/Podsディレクトリの中のObjective-Cソースがダメらしい。
なのでvendor/Staticディレクトリを作成し、その下にObjective-Cコードを入れる。

今回はネットワーク状態を確認するためのコードを導入したかった。
調べるとAppleがサンプルコードを用意してくれてた。
https://developer.apple.com/Library/ios/samplecode/Reachability/Introduction/Intro.html

これの中のReachability.hとReachability.mをvendor/Static
の下に入れる。
Rakefileは以下のように編集。

  app.vendor_project("vendor/Static",:static)

で使ってみると、結果が返ってくる。素晴らしい。楽。

common.rb
Reachability.reachabilityWithHostName("www.google.com")
6
6
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
6
6