Programming in Objective-C 2.0

A Complete Introduction to the Objective-C Language for Mac OS X and iPhone Development
http://classroomM.com/objective-c

Chapter 1 Introduction

Objective-C was layered on top of C-language, extensions was added to C to create a new language that objects can be created and manipulated.
A framework is a set of classes and routines.

Chapter 2 Programming in Objective-C

To use Xcode to develop our program, it's not easy to build Mac application via terminal because there are many things need to be packaged in an application bundle.
File extensions:



  • .m is used for the Objective-C source file





  • .mm is used for Objective-C++ source file





  • NSLog is a function for printing debug statement to the console. It works like fprintf(stderr,"format_string, args...) but its format string is a NSString object rather than a simple string char*.

    Chapter 3 Classes, Objects, and Methods

    In Objective-C, the syntax for applying methods to classes and instances:



    [ ClassOrInstance method ]
     

    To define a new class:

    @interface NewClassName: ParentClassName
    {
    memberDeclarations;
    }
    methodDeclarations
    @end 

    Declarations of method for class/instance:

    -(return type) instanceMethod: (argType) argName;
    +(return type) classMethod: (argType) argName;

    An instance method performs some operations on a particular instance of a class.
    A class method performs some operations on the class itself such as init and alloc.

    To implement a class:

    @implementation NewClassName
    methodDefinitions;
    @end

    Chapter 4 Data Types and Expressions

    Type"id" is used to store any object of any type.

    Chapter 5 Program Looping

    Chapter 6 Making Decisions

    Type "BOOL" is defined by compiler's pre-processor.

    Chapter 7 More on Classes

    Separate Interface and Implementation Files

    The declaration(@interface section) of a class is placed in a class.h file, the definition(@implementation section) of a class is places in the file with the same name but extension .m.

    Synthesized Accessor Methods

    All instance variables are private in Objective-C by default, you need to use accessor methods to get and set variable's values.
    "Properties" is a features in Objective-C that allows you to generate accessors automatically.



  • Use the @property directive in class's declaration to identify properties(instance variables)





  • use the @synthesize directive in class's definition





  • Accessing Properties




  • [instance property]





  • instance.property





  • Multiple Arguments to Methods

    The self Keyword

    You can use the keyword self to refer to the object that receives the message.


    Chapter 8 Inheritance


    It All Begins at he Root

    Finding the Right Method

    Extension Through Inheritance

    The @class Directive

    It tells the compiler that the class is defined somewhere out of this file.
    If you need to reference that class' methods, the @class directive would not suffice.

    Overriding Methods

    You can change the definition of the inherited method by overriding it.
    A method defined with the same name as that of its parent overrides the inherited definition.

    Abstract Classes

    Sometimes, classes are created just to make it easier for someone to create a subclass.
    For that reason, theses classes are called abstract classes.
    Methods and instance variables are defined in the class, but no one is expected to create an instance from that class.



    Chapter 9 Polymorphism, Dynamic Typing, and Dynamic Binding

    Chapter 21 Writing iOS Applications

     

    留言

    熱門文章