SEL s2 = @selector (eat:);
[Ani performselector:s2 withobject:@ "a lollipop stained with Baba"];
[Ani performselector: @selector (eat:andfoodname:)
Withobject:@ "The monitor raises the vicious dog" withobject:@ "a piece stained with Baba Lollipop"];
SEL (is a type that contains an address)
ID Type:
Both NSObject and ID types can point to any object
NSObject Compile-time check (requires coercion of type conversions)
ID does not require coercion type conversion, ID can be used directly
The compiler sees the ID type, which is considered to be a dynamic type, not a check type
23) Polymorphism:
Parent class cannot access child class methods
The concept of polymorphism: the ability of different objects to respond to the same name in their own way is called a polymorphic
Show: The pointer of the parent class points to the object of the child class
Conditions of polymorphism: 1) having an inheritance relationship
2) There is a method override (subclass overrides the parent class with the same name method)
Use of polymorphism Note:
1) Use a subclass method if this method is not in the parent class, use subclasses to force type conversions
How to get the class object:
Class object belongs to class type
1) Get through the instance object
Class C1 = [D class];
Class C2 = [D1 class];
2) Get class object by class name
Class C3 = [Dog class];
NSLog ("%p", C3);
24) Construction Method:
The inner part of the new method calls two method classes to complete 3 things:
1) Use the Alloc method to allocate storage space (returns the allocated object);
2) Initialize the object using the Init method;
3) Return the first address of the object
Init is an object method
[Person Alloc], memory has been cleared 0 (where the properties are initialized by 0)
OC constructs the method to learn which content:
Learn how to override the construction method so that after the object is created, there is an initial value
Super refers to the parent class object
25) Custom Construction method:
1) is an object method:
2) Return is ID type (instancetype)
3) The method name must be Initwith
-(Instancetype) Initwithname: (NSString *) name andage: (int) age{...}
Person *P1 = [Person alloc] initwithname:@ "Zhang San Fung" Andage:
The SEL and ID of OC