I dont know where to go (at compile time)

I have used Objective-C for a long time and I love it. After using Clascal, ObjectPascal and Smalltalk for some years I bought a NeXT Cube some 20+ years ago and found a language that almost gave me the dynamic of Smalltalk and the power of C. Winking
The Objective-C language has something that most other compiled language lacks, a runtime engine. This engine gives the program the ability to communicate with the ‘language’ at runtime, and make the language do many things the compiler does. So even if the compiler is not actually there when the program runs, the program can still ask about how it’s components and it’s even able to make changes and extensions to itself. This may at first seems unneeded but after working with Objective-C for a time you will see the benefits and even become addicted.

There are many new users of Objective-C now, because iOS have grown so popular and they using the blog media is writing tons of tips and tricks how to do wonders with the AppKit and the UI. Fortunately there are also some blogs written by wizards that has been digging deep into the language and is sharing their wisdom about this runtime engine. Here comes some of my favorite blogs I read in this subject:

At first - Martin Pilkinton - and his blog Pilky.me, has an article on the basics of the Runtime and how the object model of Objective-C is constructed. This is a good start.

Next, - Mike Ash’s NSBlog (@mikeash), here you will find your main source of C and Objective-C inner workings. The Objective-C runtime has an API of C functions but most of us thinks it is easier with messages. Mike has encapsulated the runtime in Objective-C classes and with those we don’t have to handle pointers and functions. His little kit is found on GitHub, clone it.

Switching and adding methods at runtime seems a little ‘Look what I have done!’ but in the comments section of this blog entry made by Scott Stevenson (@scottstevenson) about adding methods there is a discussion about its usefulness.

Also at the NSConference 2010 Jeff LaMarche (@jeff_lamarche) made a speech about how he uses the runtime’s abilities. Pat Zearfoss wrote about and linked it here, watch it.

Some years ago on WWDC Steve Naroff asked the crowd what we liked to see in a new version of Objective-C, some of us shouted instance variables added with categories. This was one of my most longed for feature in the old NeXT times Objective-C implementation even if I found a hack reusing some pointer in the class to add an NSDictionary.
So, last (but not least) one of my favorite blogger Ole Begemann (@elo) has now pointed out a trick to add instance variables, sort of, to categories. He uses a new feature in Objective-C 2.0 using the runtime (thank you Mr. Naroff) to do this. So, Ole’s has now found a nicer and cleaner solution than my old one and writes about it here.

There are many more links about this subject and I will try to link to and write about them in another entry.

blog comments powered by Disqus