OC&swift runtime 六 Adding Classes

方法一: objc_allocateClassPair
Discussion:创建一个新类和对应的元类
OC

Class objc_allocateClassPair(Class superclass, const char *name, size_t extraBytes);
Class DXArrayClass = objc_allocateClassPair([NSArray class], "DXArray", 0);

Swift

func objc_allocateClassPair(_ superclass: AnyClass?, _ name: UnsafePointer, _ extraBytes: Int) -> AnyClass?

方法二: objc_disposeClassPair
Discussion:销毁一个和他的元类
OC

void objc_disposeClassPair(Class cls);

Swift

func objc_disposeClassPair(_ cls: AnyClass)

方法三: objc_registerClassPair
Discussion:用来注册objc_allocateClassPair被alloc的类
OC

void objc_registerClassPair(Class cls);
objc_registerClassPair(DXArrayClass);

Swift

func objc_registerClassPair(_ cls: AnyClass)

你可能感兴趣的:(OC&swift runtime 六 Adding Classes)