Objective-C is a good language. I enjoy using it more than many other technologies out there. I will however, knock Obj-C for it’s verbosity. You’re going to be doing some typing. That’s for sure.
There are many people out there who are trying to get around Obj-C for iPhone development all together. iPhone Wax lets you use Lua, Flash compiles down to an Xcode project, and Taplynx doesn’t look like it requires any code at all.
I do not think any of these technologies are a good idea for professional programmers. I am comfortable with doing my own memory management, and I don’t see a reason to add a very large dependency to your app. I do however find it helpful to attempt to generate some of these piles of code you’re going to be needing.
In this series of posts I will show you how I save time by using Ruby to generate Objective-C code for my iPhone application. As Obj-C and the Apple frameworks improve, the scripts in these post may become unnecessary, but until that time comes I’ll be keeping a terminal window open to my ~/scripts directory.
We’re going to start out really simple here. One point of excessive typing that I frequently encounter is UIColor. My designer coworker frequently presents me with hex values for colors in the app. I’d often end up with four lines of code or one totally unreadable line to get that color into the app. So here is a very basic Ruby script that I wrote to take care of this problem.
rgb = ARGV[0]
exit if rgb.nil? or rgb.length != 6
r = rgb[0..1].to_i(16)
g = rgb[2..3].to_i(16)
b = rgb[4..5].to_i(16)
puts "\n// Hex ##{ARGV[0]} -- r: #{r} g: #{g} b: #{b} "
puts "[UIColor colorWithRed:#{r/255.0} green:#{g/255.0} blue:#{b/255.0} alpha:1.0];\n\n"
To use it you just pass the hex code (with no #) as the first arg.
and just like that you’ve got
[UIColor colorWithRed:0.784313725490196 green:0.305882352941176 blue:0.674509803921569 alpha:1.0];
That’s it. Now this might seem pretty trival, but we are going to get much more involved as this series of posts goes on. Once you have a nice sized dir of these, you’ll be amazed at how useful they can be.