iOS Development written questions
One, OC Grammar part:
1, the meaning of description attribute in NSObject, can it be rewritten?
- Example of usage : Defining a Person class, declaring two member variables
@interface Person: NSObject
{
nsstring * name;
int age;
}
- In the implementation of the class, the Init method initializes the member variable
@implementation person
-(Instancetype) init
{
self = [super init];
if (self) {
name = @ " Lao li ";
age = ;
}
returnself;
}
- To override the description method:
-(nsstring *) description
{
return [nsstring stringwithformat:@ " name:%@, Age:%d ", Name,age];
}
- When this class is used, a person object is instantiated and the description method is automatically called when the object is log.
Person * Laoli = [ person new];
NSLog (@ "%@", Laoli);
- The output results are as follows:
Name: Lao Li, Age: -
- Here's the description method that acts as a description object:
- If the description method is not overridden, the direct NSLog (@ "%@", Laoli) is obtained, and the output result is the class and memory address that the object belongs to:
<Person:0x10010bbd0>
2.