1. Methods for replacing private classes at Object-c run time
Runtime full interpretation
2. Add a method to an object at run time
C method form definition of the added method
void Hellolog (id self, SEL _cmd)
{
NSLog (@ "Hellolog");
}
Oc method form definition is added method
-(void) Hellolog
{
NSLog (@ "Hellolog");
}
Classes that require new methods
Class Newclass = [NSObject class];
C Method Form
Class_addmethod (Newclass, @selector (Hellolog), (IMP) hellolog, "[email protected]:");
Oc Method Form
Class_addmethod (Newclass, @selector (Hellolog), (IMP) hellolog, "[email protected]:");
Call New method
id instance = [[NSObject alloc] init];
[Instance Performselector: @selector (Hellolog) Withobject:nil];
The OBJECTIVE-C runtime defines several important types.
Class: Defining the Objective-c Class
Ivar: Defines an instance variable of an object, including the type and name.
Protocol: Define formal agreements.
objc_property_t: Defines a property. This name may be called to prevent conflicts with user types in Objective-c 1.0, when there are no attributes.
Method: Defines an object method or class method. This type provides the name of the method (that is, the * * selector), the number and type of parameters, and the return value (which together is called the * * Signature of the method), and a function pointer to the code (that is, the method's implementation * *).
SEL: Defines the selector. The selector is a unique identifier for the method name.
IMP: Defines the method implementation. This is just a pointer to a function that takes an object, a selector, and a variable-length argument list (varargs), returning an object
Run Time runtime