PDF Ebook From C ++ to Objective-C

Submitted by antoq on Sat, 07/18/2009 - 07:43

This document is designed to act as a bridge between C ++ and Objective-C. Many texts exist to teach the object model through Objective-C, but to my knowledge, none target advanced C ++ developers wanting to compare these concepts with their own knowledge. At first, the Objective-C language seems to be an obstacle rather than a boost for Cocoa programming (cf. section 1 on the following page): it was so different that I couldn’t get into it.

It took me some time to appreciate its challenges, and understand the many helpful concepts it supplies. This document is not a tutorial, but a quick reference, to these concepts. I hope that it will be useful in preventing a developer from either abandoning Objective-C or misusing its features, because of a misunderstanding of the language. This document does not claim to be a full reference, but a quick one. For detailed explanations of a concept, be sure to read a specialized Objective-C manual.

Contents
Introduction
1 Objective-C and Cocoa
2 A short history of Objective-C
3 Syntax overview

    3.1 Keywords
    3.2 Comments
    3.3 Mixing up code and declarations
    3.4 New types and values
      3.4.1 BOOL, YES, NO
      3.4.2 nil, Nil and id
      3.4.3 SEL

    3.5 Class names: why NS?
    3.6 Differencing functions and methods


4 Organization of source code: .h and .m files, inclusion
5 Classes and objects

    5.1 Root class, type id, nil and Nil values
    5.2 Class declaration
      5.2.1 Attributes and methods
      5.2.2 Forward declarations: @class, @protocol
      5.2.3 public, private, protected
      5.2.4 static attributes

    5.3 Methods

      5.3.1 Prototype and call, instance methods, class methods
      5.3.2 this, self and super
      5.3.3 Accessing instance variables inside a method
      5.3.4 Prototype id and signature, overloading
      5.3.5 Pointer to member function: Selector
      5.3.6 Default values of parameters
      5.3.7 Variable number of arguments
      5.3.8 Anonymous arguments
      5.3.9 Prototype modifiers (const, static, virtual, ‘‘= 0’’, friend, throw)

    5.4 Messages and transmission

      5.4.1 Sending a message to nil
      5.4.2 Delegating a message to an unknown object
      5.4.3 Forwarding: handling an unknown message
      5.4.4 Downcasting

6 Inheritance

    6.1 Simple inheritance
    6.2 Multiple inheritance
    6.3 Virtuality
      6.3.1 Virtual methods
      6.3.2 Silent redefinition of virtual methods
      6.3.3 Virtual inheritance

    6.4 Protocols

      6.4.1 Formal protocol
      6.4.2 Informal protocol
      6.4.3 Message qualifiers for distant objects

    6.5 Class categories
    6.6 Joint use of protocols, categories, subclassing:

7 Instantiation

    7.1 Constructors, initializers
      7.1.1 Distinction between allocation and initialization
      7.1.2 Using alloc and init
      7.1.3 Example of a correct initializer
      7.1.4 Initialization failure
      7.1.5 Default constructor : designated initializer
      7.1.6 List of initialization and default value of instance data
      7.1.7 Virtual constructor
      7.1.8 Class constructors

    7.2 Destructors
    7.3 Copy operators

      7.3.1 Classical cloning, copy and copyWithZone:
      7.3.2 NSCopyObject()
      7.3.3 Dummy-cloning, mutability, mutableCopy and mutableCopyWithZone:

8 Memory management

    8.1 new and delete
    8.2 Reference counting
    8.3 alloc, copy, mutableCopy, retain, release
    8.4 autorelease
      8.4.1 autorelease
      8.4.2 The autorelease pool
      8.4.3 Using several autorelease pools
      8.4.4 Caution with autorelease
      8.4.5 autorelease and retain
      8.4.6 Convenience constructor, virtual constructor
      8.4.7 Setter
      8.4.8 Getter

    8.5 Retain cycles
    8.6 Garbage collector

9 Exceptions
10 Strings in Objective-C

    10.1 The only static objects in Objective-C
    10.2 NSString and encodings
    10.3 Description of an object, %@ format extension, NSString to C string

11 STL and Cocoa

    11.1 Containers
      11.2 Iterators
      11.2.1 Classical enumeration
      11.2.2 Fast enumeration

    11.3 Functors (function objects)

      11.3.1 Using selectors
      11.3.2 IMP caching

    11.4 Algorithms

12 C++ specific features

    12.1 References
    12.2 Inlining
    12.3 Templates
    12.4 Operators overloading
    12.5 Friends
    12.6 const methods
    12.7 List of initialization in the constructor

13 RTTI (Run-Time Type Information)

    13.1 class, superclass, isMemberOfClass, is Kind Of Class
    13.2 conformsToProtocol
    13.3 respondsToSelector, instancesRespondToSelector
    13.4 Strong typing or weak typing with id

14 Objective-C++
15 Objective-C 2.0
Conclusion
References
Document revisions
Index

Download
PDF Ebook From C ++ to Objective-C


Posted in :