49

Hi I'm looking into iPhone development, and Objective-C is not be my preferred language. As far as I can see at this moment Ruby cannot be used to talk to Cocoa Touch at the moment on the iPhone.

So my question is, am I wrong? Can I use Ruby on the iPhone to develop Cocoa Touch applications. And what is the future looking like for Ruby on the iPhone?

pasawaya
  • 11,515
  • 7
  • 53
  • 92
BefittingTheorem
  • 10,459
  • 15
  • 69
  • 96
  • 3
    Apple just relaxed the restrictions on dev tools for apps in the App store: http://www.apple.com/pr/library/2010/09/09statement.html – Kjetil Ødegaard Sep 09 '10 at 18:57
  • Hi, 3+ years later & there's a new movement which is attempting to get Apple to provide MacRuby for iOS :) Read more about it here - http://welovemacruby.com/ & please make sure you file that bug report :) – gef Dec 06 '11 at 20:59
  • Good to see, I presume Apple is considering MacRuby internally – BefittingTheorem Dec 07 '11 at 16:47

17 Answers17

75

Now you can with RubyMotion

gimenete
  • 2,649
  • 1
  • 20
  • 16
49

In the iPhone OS, mprotect() will fail if you try to use it to mark writable sections of memory as executable. This breaks bridges like RubyCocoa (and probably MacRuby) that use libffi to create Objective-C method handlers at runtime. I believe that this is by design because it was not always the case.

Ultimately, this is more a matter of platform politics than technology, but a technical workaround for this exists. Instead of generating custom method handlers at runtime, precompile a pool of reconfigurable ones that are assigned as needed, essentially making the bridging process entirely data-driven. As far as I know, this is not yet being done in RubyCocoa or MacRuby.

Another significant thing to consider is that the compiled Ruby and RubyCocoa runtimes can be significantly larger than compiled Objective-C apps. If these libraries were available on the iPhone, this wouldn't be an issue, but for now, even if you had RubyCocoa working, you might not want to use it for apps that you distribute.

Tim Burks
  • 539
  • 1
  • 3
  • 4
22

No, you are correct. Currently, and most likely for the foreseeable future, Ruby will not be an option, at least for AppStore applications. There's no reason you couldn't do this on a Jailbroken phone, but Apple is pretty wed to Objective C for official development.

Ben Gottlieb
  • 85,404
  • 22
  • 176
  • 172
12

You are better off as a programmer knowing a number of different languages - think of Objective-C as a good learning opportunity.

I've found that things you learn in other languages often make you a better programmer overall, and give you new insights into other languages you already know.

Kendall Helmstetter Gelner
  • 74,769
  • 26
  • 128
  • 150
  • 3
    I totally agree on learning new languages, as it's something I enjoy a lot. To be honest I'm not looking forward to returning to C style languages, as I find C to be overly cryptic for application level programming. Objective-C is certainly more usable than C++ though, so I can be thankful for that – BefittingTheorem Oct 22 '08 at 07:13
  • 5
    The language is not the only reason I prefer one language over another -- I continue to make significant investment in libraries and tools. Not having these libraries available significantly impacts development time. – Shane Holloway Feb 28 '10 at 04:30
  • 4
    Although I totally agree, this is an advice, not an answer. – edgerunner Jul 23 '11 at 09:04
  • 1
    It is an answer in that I think it's wrong to develop using the non-native language even if it works. Sometimes it's better to answer the question they didn't ask but should have. – Kendall Helmstetter Gelner Jul 23 '11 at 16:05
  • This would make a good comment, but it does not answer the question. – iconoclast Jul 19 '12 at 01:13
  • Yes it does. If I *must* spell out the implication of my words, the answer is you CAN use Ruby, but you SHOULD use Objective-C if only for personal improvement. – Kendall Helmstetter Gelner Jul 21 '12 at 15:32
  • If I asked you how to get to the nearest McDonalds, and you said "you're better off going to Burger King" that doesn't answer the question. It may reply to it, but it doesn't supply the requested information. There's nothing in your reply that says "yes you can do it, and here's how". Furthermore, at the time you gave the reply, the answer *was* "no you cannot". – iconoclast Aug 22 '12 at 23:04
  • Your response would make sense in a vacuum. But there were plenty of other people telling him how to go to a McDonalds (use Ruby if possible), so an additional answer (that I knew would not ever be marked as correct), is helpful to add to the discussion so people can correctly decide if using an alternate development platform is right for them. Always err on the side of providing helpful details, rather than withholding them. – Kendall Helmstetter Gelner Aug 23 '12 at 03:02
8

rhomobile is an option to run ruby code on the iPhone, but it's essentially web app development. A web server runs locally on the iPhone and your ruby code renders to standard client side web technologies (html/css/javascript).

http://rhomobile.com/

pfeilbr
  • 1,939
  • 4
  • 19
  • 18
7

Actually, the ruby cocoa bridge isn't awkward at all; things work remarkably smoothly, right down to connecting outlets in IB etc. The resulting code is down right beautiful.

As for iPhone development, if you want an official AppStore application, you're out of luck unfortunately. Apple dictated that iPhone is Obj-C/Cocoa Touch, and there's a clause in the SDK license saying that one of the things they will reject an app for is having a language interpreter/JIT compiler, so you couldn't add a ruby interpreter in your app yourself.

Off topic, but hilariously, this is why Flash for the iPhone is Adobe blowing smoke. They couldn't get a swf player onto the AppStore even if they wanted to, per Apple's license.

Jon Raphaelson
  • 1,244
  • 1
  • 9
  • 10
  • 4
    Flash for iPhone can still happen if Apple license it. The agreement allows for explicit licensing, it just provides a barrier for any old interpreter being installed. – Andy Dent Jan 27 '09 at 02:54
  • I don't think they will reject the app. The app simply won't run. The OS will not execute instructions off the memory heap. – jrwren Jun 07 '11 at 14:19
4

Uh, Rhodes (Rhomobile) does allow you to do native apps on the iPhone and all other smartphones. Yes, we do leverage doing rendering via the WebUIView control. But we allow all device capabilities and synchronized local data.

Adam Blum
  • 595
  • 4
  • 3
4

You might want to take a look at shinycocos. It is a child project of cocos2d-iphone, an Objective-C game programming framework for iPhone.

I haven't yet played with it, but from the git README I infer that it bundles Ruby 1.9.1 into your app.

Radamanthus
  • 690
  • 2
  • 5
  • 17
  • I looked at shinycocos too sometime ago, I couldn't get it installed so I switched to obj-c to learn it... but they're developing real games with it... and in ruby!!! so it definately worths a try!! – makevoid Mar 17 '10 at 22:34
4

I installed the ruby package from Cydia on my iPod Touch 1G jailbroken on 3.1.3:

image

Seems to work.

Now as for cocoa-touch that is a whole different story I would assume.

Community
  • 1
  • 1
Steven Lu
  • 41,389
  • 58
  • 210
  • 364
  • I see some more downvotes for this post now, this post is obviously going to need to be updated as it is almost 3 years. I'm sure there is still a way to run ruby in very much the same way and I'd be surprised if the `ruby` Cydia package isn't still there. – Steven Lu Mar 12 '13 at 19:25
2

Take a look at http://www.appcelerator.com/products/titanium-mobile/ "Native iPhone and Android apps built with Web technologies."

Sounds good isn't it ? ;-)

fro_oo
  • 1,610
  • 4
  • 24
  • 46
2

No you can not create iOS native app in Ruby. There is only two options for native apps for mac and iOS:-

Objective C and Swift Programming Language

Tutorials:-

Apple's official tutorial on Objective C

Apple's official tutorial on Swift Programing Language

If you are familiar with Ruby and only want to create iOS apps by Ruby. Ruby Motion, can be a cross-platform option for you, but it is not free.

Cross-Platforms

Mayank Jain
  • 5,663
  • 7
  • 32
  • 65
1

I imagine it won't work right now, but I'd imagine that you'll eventually be able to use MacRuby to build iphone apps. Apple are putting a lot of work into it

Here's a link to an ADC article describing how to build normal cocoa apps

Orion Edwards
  • 121,657
  • 64
  • 239
  • 328
1

You don't have to use Objective-C to write iPhone apps. If you use QuickConnectiPhone, http://sourceforge.net/projects/quickconnect/, you can write it completely in JavaScript, CSS, and HTML and still have an installable application not a web app.

If you know ruby you are probably working with JavaScript already.

To see how to install it, run it, and other ideas go to tetontech.wordpress.com

Lee
  • 751
  • 5
  • 2
0

There's an open-source Ruby-Cocoa bridge you might try to get working. But I gather that there's a bit of an impedance mismatch between Ruby and ObjC that makes it a bit awkward to use.

Menkboy
  • 1,595
  • 10
  • 12
0

The Ruby Cocoa bridge probably will not work. Most of the bridges for dynamic languages need to generate executable thunks (either manually or with libffi). More limited bridges (for more static languages) may not have such issues.

In either event, bringing up a bridge is probably going to require becoming more familiar with the Objective C runtime than one would just learning how to write Cocoa Touch apps, which probably defeats the point of doing it in the first place.

Louis Gerbarg
  • 43,356
  • 8
  • 80
  • 90
0

Currently isnt true, Apple change their policies, take a look at ShinyCocos, is a ruby bindings for the Cocos2D-iphone game framework.

https://github.com/funkaster/shinycocos

norman784
  • 2,201
  • 3
  • 24
  • 31
-1

One possible solution would be to create an application wrapping for example the rice library (google it) which includes a ruby-vm. I reckon you would be able to create c++ wrappers that you could expose to ruby, thus making an environment for iphone development with ruby. This probably requires a lot of work though ^^

Jim
  • 1