12

Sometimes it's nice to open an interpreter, type out some code and see if it's working, rather than having to compile something large like an Xcode project just to quickly test something. Does an Objective-C Interpreter exist for the Mac, or am I out of luck?

UPDATE: There's a paid program in the App Store called CodeRunner, which lets you run Obj-C quickly (and several other languages). It's not an interpreter, but works pretty well for testing out ideas quickly: http://itunes.apple.com/us/app/coderunner/id433335799?mt=12

Matthew Rankin
  • 457,139
  • 39
  • 126
  • 163
Dave
  • 12,408
  • 12
  • 64
  • 67
  • 2
    Try using `clang-interpreter` (one of the examples in Clang). It is quite limited indeed, but you can extend it easily. – SK-logic Aug 27 '11 at 11:48
  • You want Lisp! https://github.com/byulparan/cl-nextstep/ Scheme! https://github.com/maitria/gambit-objc (currently broken unfortunately) – Jeremy Field Aug 09 '23 at 05:45

3 Answers3

13

You can use F-Script, which is Smalltalk-based, but lets you interface with Cocoa. You can also embed it in your application, to let you inspect views and other things at runtime. It's quite useful. Edit: as pointed out in the comments, there are other great language bridges available, like PyObjC, RubyCocoa/MacRuby, Nu, etc. CINT is an example of a C interpreter, but not Obj-C.

As for an actual Objective-C interpreter, I don't think one really exists. But it's not too hard to set up a "Command Line Tool" project in Xcode, which gives you a really simple main.m file to try something in.

jtbandes
  • 115,675
  • 35
  • 233
  • 266
  • 1
    I also have a, er... s-load of small test console programs in my source folder. The only problem is the name. In Delphi, projects get a default name ProjectN, where N is a running number (Delphi checks if it already exists). For most test projects, that is fine with me. Something like it would make things easier in Xcode, IMO. Can one write plugins for Xcode? – Rudy Velthuis Aug 26 '11 at 23:40
  • Sounds like [it's possible](http://stackoverflow.com/questions/6316921/xcode-4-plugin-development). – jtbandes Aug 26 '11 at 23:41
  • 4
    Other interpreted languages on the objective-c runtime are [Nu](http://programming.nu/index) and [MacRuby](http://www.macruby.org/). For quickly trying out C stuff (arithmetic, type casting, etc.), I've found [CINT](http://root.cern.ch/drupal/content/cint) useful. – mckeed Aug 27 '11 at 00:06
  • 3
    There's also [PyObjC](http://pyobjc.sourceforge.net/documentation/pyobjc-core/intro.html) (installed by default on Snow Leopard; dunno about Lion) -- you can access pretty much all of Cocoa from a Python interpreter session: `from Cocoa import *`. – jscs Aug 27 '11 at 01:22
  • +1 for python! It works like a charm, and it works great for scripts you can use with your project, like ones that can read Core Data models, for example. – Cameron Spickert Aug 27 '11 at 01:48
  • +1 for the "Command Line Tool". To create a "Command Line Tool" project in objective-c, choose type "Foundation" – GabLeRoux Dec 07 '13 at 18:37
5

For those arriving here late: Take a look at Tosti. A basic but pretty functional Objective-C interpreter.

It's a side-project I put on GitHub as there seems very little available at the moment. I'm using it to do some remote debugging. Support available.

leo
  • 7,518
  • 1
  • 24
  • 25
0

RubyMotion allows you to use all of the Cocoa SDK's library (as far as I know there are 0 limitations due to the similarities between Ruby & Objective C), for example, at runtime. You can also of course use every Objective C library you can load into it as well. The only limitations are the same as all other IDE's, namely those set forth by Apple with regard to unapproved dynamic libraries.

Anyway, functions are syntactically very, very similar to Objective-C, in it surprised me that you can do this in such a way with ruby (normally you can't

#for example the in AppDelegate class
class AppDelegate
  def application(application, didFinishLaunchingWithOptions:launchOptions)
    #...
    true
  end
 end

when you run rake (equivalent to Build command in XCode), you of course do it from the console, and once your iPhone/iPad app is loaded to the simulator or your apple device, you then can control that device or simulator interactively via commands entered from the console.

Ruby Motion costs $200 bucks/year, so its not worth it just for the interactive shell feature though of course

boulder_ruby
  • 38,457
  • 9
  • 79
  • 100