1. Write an implementation of the NSString class:
+ (ID) initwithcstring: (const char *) nullterminatedcstring encoding: (nsstringencoding) encoding;
+ (ID) stringwithcstring: (const char *) nullterminatedcstring encoding: (nsstringencoding) Encoding {
NSString *obj;
obj = [self allocwithzone:nsdefaultmalloczone ()];
obj = [obj initwithcstring:nullterminatedcstring encoding:encoding];
return autorelease (obj);
}
The above code means: Set up the object requires two steps 1) first allocate memory space for the object
2) then initialize the object
1) Allocate memory space: the class to send +alloc or +allocwithzone: Message to object.
This is the common [Class alloc].
or an uncommon [Class allocwithzone:nsdefaultmalloczone ()].
2) Initialize: To invoke the-init method for initialization,
All kinds of-init methods for or without parameters are counted.
The above method of creating the object, the return value to be sent to the object is automatically released in the pool
iOS face questions