Objective:
Recently study runtime, feel that the inside of the thing is very deep, so decided to first the Apple to provide a simple translation of the runtime.h file, about the usage will be a few share after.
/*Types*/#if! objc_types_defined///An opaque type is represents a method in a class definition.typedefstructObjc_method *Method;///An opaque type the represents an instance variable.typedefstructObjc_ivar *Ivar;///a opaque type that represents a category.typedefstructObjc_category *Category;///An opaque type the represents an Objective-c the declared property.typedefstructObjc_property *objc_property_t;
These four type are:
(a method of an indeterminate type in a Class), (an instance variable of an indeterminate type), (a class of indeterminate type), (an indeterminate attribute declaration of OC)
structObjc_class {class Isa objc_isa_availability;#if!__objc2__Class Super_class objc2_unavailable; Const Char*name objc2_unavailable; Longversion objc2_unavailable; Longinfo objc2_unavailable; Longinstance_size objc2_unavailable; structObjc_ivar_list *Ivars objc2_unavailable; structObjc_method_list * *methodlists objc2_unavailable; structObjc_cache *Cache objc2_unavailable; structObjc_protocol_list *protocols objc2_unavailable;#endif} objc2_unavailable;/*Use ' Class ' instead of ' struct objc_class * '*/#endif
This is the definition of a objc_class structure;
#ifdef__objc__@classProtocol;#elsetypedefstructObjc_object Protocol;#endif///defines a methodstructobjc_method_description {SEL name; /**< The name of the method*/ Char*types;/**< The types of the method arguments*/};///defines a property attributetypedefstruct { Const Char*name;/**< The name of the attribute*/ Const Char*value;/**< The value of the attribute (usually empty)*/} objc_property_attribute_t;
This code, I understand is the definition of the two structure, about the structure, there is an opportunity to write a piece of content ;
/*Functions*//*working with Instances*//** * Returns A copy of a given object. * * @param obj an Objective-c object. * @param size the size of the object \e Obj. * * @return A copy of \e obj.*/Objc_exportIDObject_copy (IDobj, size_t size) __osx_available_starting (__mac_10_0, __iphone_2_0) objc_arc_unavailable;/** * frees the memory occupied by a given object. * * @param obj a Objective-c object. * @return Nil*/Objc_exportIDObject_dispose (IDobj) __osx_available_starting (__mac_10_0, __iphone_2_0) objc_arc_unavailable;/** * Returns The class of an object. * * @param obj, the object want to inspect. * * @return the Class object of Which \e object is a instance, * or \c nil if \e object is \c nil. */objc_export Class Object_getclass (IDobj) __osx_available_starting (__mac_10_5, __iphone_2_0);/** * Sets the class of an object. * * @param obj-the object to modify. * @param CLS A class object. * @return The Previous value of \e object ' s class, or \c nil if \e object is \c nil. */objc_export Class Object_setclass (IDobj, Class cls) __osx_available_starting (__mac_10_5, __iphone_2_0);/** * Returns Whether an object is a class object. * * @param obj a Objective-c object. * @return True if the Obje CT is a class or Metaclass, False otherwise. */objc_export BOOL Object_isclass (IDobj) __osx_available_starting (__mac_10_10, __iphone_8_0);/** * Returns The class name of a given object. * * @param obj an Objective-c object. * @return The name of the CLA SS of which \e obj is an instance. */Objc_exportConst Char*object_getclassname (IDobj) __osx_available_starting (__mac_10_0, __iphone_2_0);
Starting with/*functions*/is some method (all instance methods):
1, id object_copy (ID obj, size_t size) returns a copy of the passed object, the required parameter is an OC object, and the size of the object
2, ID object_dispose (ID obj) frees the memory of the given object
3. Class Object_getclass (ID obj) returns the classes of the object
4, class Object_setclass (ID obj, class CLS) sets the classes of the object, the argument is the object to be modified, a class object
5, BOOL object_isclass (ID obj) returns whether an object is a class object
6, const char *object_getclassname (ID obj) returns the class name of the given object (note: The class name is an instance of this object?). )
/** * Returns a pointer to any extra bytes allocated with an instance given object. * @par Am obj an Objective-c object. * * @return A pointer to any extra bytes allocated with \e obj. If \e obj was * not allocated with any extra bytes and then dereferencing the returned pointer is undefined. * * @note This function returns a pointer to any extra bytes allocated with the instance * (as specified by \c Class_cre Ateinstance with extrabytes>0). This memory follows the * object ' s ordinary Ivars, and May is not a adjacent to the last Ivar. * @note The returned pointer is guaranteed to being pointer-size aligned, even if the area following * The object's last IVA R is less aligned than. Alignment greater than pointer-size is never * guaranteed, even if the area following the object's last Ivar was more Alig Ned than that. * @note in a garbage-collected environment, the memory is scanned conservatively. */Objc_exportvoid*object_getindexedivars (IDobj) __osx_available_starting (__mac_10_0, __iphone_2_0) objc_arc_unavailable;/** * Reads The value of a instance variable in an object. * * @param obj The object containing the instance variable whose value want to read. * @param Ivar The Ivar describing the instance variable whose value you want to read. * * @return The value of the instance variable specified by \e Ivar, or \c nil if \e object is \c nil. * * @note \c Object_getivar is faster than \c object_getinstancevariable if the Ivar * for the instance variable is Alre Ady known. */Objc_exportIDObject_getivar (IDobj, Ivar Ivar) __osx_available_starting (__mac_10_5, __iphone_2_0);/** * Sets the value of a instance variable in an object. * * @param obj The object containing the instance variable whose value want to set. * @param Ivar The Ivar describing the instance variable whose value you want to set. * @param value The new value for the instance variable. * * @note \c Object_setivar is faster than \c object_setinstancevariable if the Ivar * for the instance variable is Alre Ady known. */Objc_exportvoidObject_setivar (IDobj, Ivar Ivar,IDvalue) __osx_available_starting (__mac_10_5, __iphone_2_0);/** * Changes the value of a instance variable of a class instance. * @param obj A pointer to an instance of a Clas S. Pass the object containing * The instance variable whose value you wish to modify. * @param name A C string. Pass the name of the instance variable whose value wish to modify. * @param value The new value for the instance variable. * * @return A pointer to the \c IVAR data structure that defines the type and * name of the instance variable specified by \e name. */objc_export Ivar object_setinstancevariable (IDObjConst Char*name,void*value) __osx_available_starting (__mac_10_0, __iphone_2_0) objc_arc_unavailable;/** * Obtains the value of a instance variable of a class instance. * @param obj A pointer to an instance of a Clas S. Pass the object containing * The instance variable whose value you wish to obtain. * @param name A C string. Pass the name of the instance variable whose value wish to obtain. * @param outvalue on return, contains a pointer to the value of the instance variable. * * @return A pointer to the \c IVAR data structure that defines the type and name of * The instance variable specified by \e name. */objc_export Ivar object_getinstancevariable (IDObjConst Char*name,void**outvalue) __osx_available_starting (__mac_10_0, __iphone_2_0) objc_arc_unavailable;/*Obtaining Class Definitions*//** * Returns The class definition of a specified class. * * @param name The name of the class to look up. * * @retur n the class object for the named class, or \c nil * If the class isn't registered with the OBJECTIVE-C runtime. * * @note \c Objc_getclass is different from \c Objc_lookupclass on that if the class * is not registered, \c OBJC_GETCL Calls the class handler callback and then checks * A second time to see whether the class is registered. \c Objc_lookupclass does * Not call the class handler callback. * * @warning Earlier implementations of this function (prior to OS X v10.0) * Terminate the program if the class does no T exist. */objc_export Class Objc_getclass (Const Char*name) __osx_available_starting (__mac_10_0, __iphone_2_0);/** * Returns The metaclass definition of a specified class. * * @param name The name of the class to look up. * * @r Eturn the \c class object for the metaclass of the named class, or \c nil if the class * isn't registered with the OBJEC TIVE-C Runtime. * * @note If the definition for the named class was not registered, this function calls the class handler * callback and Then checks a second time to see if the class is registered. However, every class * definition must has a valid Metaclass definition, and so the metaclass definition are always retur Ned, * Whether it ' s valid or not. */objc_export Class Objc_getmetaclass (Const Char*name) __osx_available_starting (__mac_10_0, __iphone_2_0);
IOS Dynamic Run Runtime runtime