Inquisitive Cocoa

22nd September ‘10

Introducing Bezier

FScript is the creation of Philippe Mougin, it’s a scripting language that is loosely based on Smalltalk but is built to use native Objective-C/Cocoa objects. It’s currently the closest thing available to a scripted version of Objective-C, with lots of nice Smalltalk-esque bonuses thrown in, like blocks (more like to Ruby’s blocks than Objective-C’s) and amazingly flexible array programming. It’s extremely cool.


Bezier acts as a viewer for FScript. It’s exactly what you get if you were to take the contents of a text file, parse it as FScript and then execute it from within a views -drawRect: method.

Bezier Screenshot

The way I tend to set things up is to first create a file with the .bezier extension using my favourite text editor (I like TextMate, particularly when used in conjunction with the FScript bundle that offers syntax highlighting, some simple snippets and basic auto-completion) and open that file in Bezier. I’ll then arrange the two windows so that they are both visible, either by placing them side by side, or on different screens, if that’s an option. Bezier will redraw it’s main view whenever it detects a changes to the file (using the AJKFileSystemObserver class) so all you need to do is write some FScript based drawing code, hit ‘Save’ and the changes should be reflected in the other window.

I find it a refreshing change to the normal Build and Run approach using Xcode, particularly when it gets down to those tiny iterations that go into honing a pixel perfect UI. If your code contains any errors then the bottom view will try to offer some useful information to help with debugging:

Bezier Error

Once you’ve refined your drawing code it’s pretty easy to convert FScript code into standard Objective-C that you can use directly in your Cocoa applications thanks to their similar basic syntax although it’s worth bearing in mind that not all of FScripts niceties will translate to Objective-C.

I hope that you’ll find Bezier to be a useful tool for prototyping UI elements in code, particularly now that resolution independence is becoming a reality thanks to the new iPhones and iPods.

It currently offers a bare minimum of features. There are a few things that I plan to add when I have a spare moment (staring with a better example file), but I’m open to any suggestions, or forks if you feel like digging into the code yourself. It’d also be nice to hear from people who end up using Bezier, maybe even see some pictures if you create something super pretty!

You can download Bezier as a binary along with a sample .bezier file, or get the source code on GitHub (MIT license).

Bezier-icon.png

Cocoa, Objective-C, Source

Add your thoughts