Matthew Robinson, Curtin University of Technology
Track: Tools & Tech; Audience: Intermediate
The Objective-C language is dynamic, many decisions are deferred from compile and link time to runtime. The dynamic nature of the language is implemented by the Objective-C runtime, which acts as a kind of operating system. Typically, you don’t need to interact with the runtime directly…
…but what can the runtime do for us if we choose to be atypical.
Categories are generally the first dynamic feature of the language that programmers new to Objective-C discover and this is where we will start. To understand how categories work we will look at message sending and method swizzling. From here we’ll be able to look at other features of the runtime.
In order to understand what the runtime is doing we will need the ability to inspect what it is doing internally, for this we will take a quick detour into DTrace profiling. We will also take a quick look at benchmarking to see if (and by how much) the dynamic nature of the language slows it down.
Messing around in the runtime has the potential to cause havoc, however, the runtime can be used to solve problems in novel and powerful ways. We will close by looking at some examples of using the runtime. Key Value Observing and Core Data are obvious examples from the Cocoa frameworks.