id
In Objective-C, object identifiers are of a distinct data type: id. This type is the general type for any kind of object regardless of class and can be used for instances of a class and for class objects themselves.
id anObject;
Till here its simple and clear
For the object-oriented constructs of Objective-C, such as method return values, id replaces int as the default data type. (For strictly C constructs, such as function return values, int remains the default type.)
didn’t understand what its talking about id replaces int? and in last inside brackets int remains the default value?
The keyword nil is defined as a null object, an id with a value of 0. id, nil, and the other basic types of Objective-C are defined in the header file objc/objc.h.
id is defined as pointer to an object data structure:
typedef struct objc_object {
Class isa;
} *id;
the above is not a obj-c syntax what is it and what it is explaining?
Every object thus has an isa variable that tells it of what class it is an instance. Since the Class type is itself defined as a pointer:
typedef struct objc_class *Class;
the isa variable is frequently referred to as the “isa pointer.”
also didn’t understand this last para.
Your book’s just being a bit confusing here. All it’s saying is that if you’re working with objects and you don’t want to get more specific,
idis a good data type to use.That’s the internal representation of an object. Your book is trying to show that an objective C object isn’t magic: under the surface it’s just a struct. The data type
idis a pointer to such a struct.In its internal data structure, each object has a pointer to another object that represents its class.
You don’t need to know this stuff if you’re just interested in programming in Objective-C (at least not while you’re learning). It does come in handy if you’re doing some advanced stuff, such as when you’re interacting with the Objective-C runtime directly.