From C++ to Objective-C
version 2.1 en
Pierre Chatelier
e-mail: pierre.chatelier@club-internet.fr
Copyright c© 2005, 2006, 2007, 2008, 2009 Pierre Chatelier
English adaptation : Aaron Vegh
Document revisions available at :
http://pierre.chachatelier.fr/programmation/objective-c.php
This document is also available in french
Ce document est aussi disponible en français
With special thanks to: For their attentive reading and many helpful comments, I would like
to thank Pascal Bleuyard, Jérôme Cornet, François Delobel and Jean-Daniel Dupas, whose
help was important in making this work the best possible. Jack Nutting, Ben Rimmington and
Mattias Arrelid have also provided many feedback. Jonathon Mah has been particularly implied
in bringing a lot of very judicious corrections.
They are not responsible of any mistake I could add after their reviewing.
1
Contents
Table of contents
2
Introduction
5
1 Objective-C and Cocoa
6
1.1 A short history of Objective-C
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6
1.2 Objective-C 2.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6
2 Syntax overview
7
2.1 Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
2.2 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
2.3 Mixing up code and declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
2.4 New types and values
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
2.4.1 BOOL, YES, NO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
2.4.2 nil, Nil and id
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
2.4.3 SEL
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8
2.4.4 @encode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8
2.5 Organization of source code: .h and .m files, inclusion . . . . . . . . . . . . . . . .
8
2.6 Class names: why NS? . . . . . . . . . . . . . . . . . . . . .