Modern Objective-C

Session 405 WWDC 2012

Objective-C is the language of choice for building great iOS and OS X apps. Dive deep into the latest advancements in Objective-C, learn how you can write more concise and less error-prone code, and find out about the advancements in Automatic Reference Counting.

I'm Patrick Beard, and I work on Objective-C.


Let me tell you, it's a real honor to get to work on this 30-year-old language.

So Objective-C's popular. And I can see that by how many of you are here today.

In the last five years, the popularity according to the TIOBE Programming Community Index has gone up from number 45 - and this is popularity in terms of search engine hits on the popular search engines - to number six last year, and this year, we've broken the top five!

I won't mention number five.

So let's talk about some of the history, just a little bit of the history of the language.

Started back in the late - early 80's, Brad Cox StepStone, in Object-Oriented C.

Very small language, I sort of think of it as the ukulele of languages: it's a very powerful but small language.

Then a little company you may have heard of: NEXT got hold of it, added some nice features to the language: Protocols, which are wonderful, and retain and release, a memory management model that allows you to write more scalable programs.

And some great frameworks, many of which we are still using today.

When we got a hold of it - Apple, that is - we added some new features.

We streamlined your code by providing properties, which automate the accessor pattern.

And we added fast enumeration, which makes your code more efficient, more concise.

Tell you, there's a theme here. We're simplifying a language, we like to say. We're adding features.

We added blocks, which make it a lot easier to do multi-threaded programming, and finally, ARC, which automates retain and release, makes the memory management a lot simpler in your program.

So we haven't been idle. This past year we've been adding some additional features to the language that I'm happy to present to you today.

These are gonna help simplify your code and help you avoid making common mistakes.

So let's start off with a very fundamental feature of the language: methods.

Methods are how you give behavior to your objects.

So everybody has written, hopefully a class like this. It has a public method, which is used by the customers of your code, and it has a private method.

In this case, the public method says: "let's play a song", we have some sort of song object.

The private method is used to manage the audio, manage the audio engines underlying the song player.

Now if you write it like I've written here, with the current compilers, the previous compilers, you're going to get a warning.

It says basically: "Hey! I have not seen this method. You're calling it before you've even declared it. What's up with that?"

Apple, Inc. AAPL
1 Infinite Loop Cupertino CA 95014 US