background preloader

Objective-C

Facebook Twitter

Understanding the Objective-C Runtime. The Objective-C Runtime is one of the overlooked features of Objective-C initially when people are generally introduced to Cocoa/Objective-C.

Understanding the Objective-C Runtime

The reason for this is that while Objective-C (the language) is easy to pick up in only a couple hours, newcomers to Cocoa spend most of their time wrapping their heads around the Cocoa Framework and adjusting to how it works. However the runtime is something that everybody should at least know how it works in some detail beyond knowing that code like [target doMethodWith:var1]; gets translated into objc_msgSend(target,@selector(doMethodWith:),var1); by the compiler. Knowing what the Objective-C runtime is doing will help you gain a much deeper understanding of Objective-C itself and how your app is run. I think Mac/iPhone Developers will gain something from this, regardless of your level of experience.

#include < stdio.h > int main(int argc, const char **argv[]) { printf("Hello World! ") [self doSomethingWithVar:var1]; gets translated to... Programming with C Blocks on Apple Devices. On Apple Devicesby Joachim Bengtsson 0Introduction In Mac OS X 10.6, Apple introduced a syntax and runtime for using blocks (more commonly known as closures) in C and Objective-C.

Programming with C Blocks on Apple Devices

These were both later back-ported to Mac OS X 10.5 and the iPhone by Plausible Labs. However, there is very little documentation on blocks; even Apple's documentation that come with 10.6 is very vague on what memory management rules apply. I hope that you can avoid all the trial-and-error that I went through with the help of this guide. This is sort of a bottom-up tutorial, going from the absolute basics in C, and moving towards higher abstractions in Objective-C. Have fun! 1What are Blocks? Counter.zip counter is an ordinary C function that returns one of these fabled blocks. Nil vs. Nil vs. NULL: The Uses And Abuses of Null Objects. One thing that developers who are new to Objective-C will notice immediately are the number of null keywords.

nil vs. Nil vs. NULL: The Uses And Abuses of Null Objects

We have a choice of: Under the hood there isn’t much difference between these (as of this writing they are all defined exactly the same way), but by convention they have some subtle variations, and they have some odd behavior around them that it pays to understand. All three of these values represent null, or zero pointer, values.

The difference is that while NULL represents zero for any pointer, nil is specific to objects (e.g., id) and Nil is specific to class pointers. It should be considered a best practice of sorts to use the right null object in the right circumstance for documentation purposes, even though there is nothing stopping someone from mixing and matching as they go along. Messaging A “cute” feature of Objective-C is that it allows messages to be passed to nil objects, simply returning a zero instead of throwing an exception. First, the good news. Cocoa for Scientists (Part XXVII): Getting Closure with Objective-C.

Author: Drew McCormack Web Sites: www.mentalfaculty.com Last week, Chris Lattner — who manages the Clang, LLVM, and GCC groups at Apple — announced that work was well underway to bring ‘blocks’ to the GCC and Clang compilers.

Cocoa for Scientists (Part XXVII): Getting Closure with Objective-C

‘So what?’ , I hear you ask, ‘My kid has been using blocks since he was 9 months old.’ Fair point, but maybe not these blocks.