Created
November 21, 2019 12:07
-
-
Save qy1010/0a568f631561f6e0215bc2a3088e6e98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class cls = objc_allocateClassPair(MyClass.class, "MySubClass", 0); | |
class_addMethod(cls, @selector(submethod1), (IMP)imp_submethod1, "v@:"); | |
class_replaceMethod(cls, @selector(method1), (IMP)imp_submethod1, "v@:"); | |
class_addIvar(cls, "_ivar1", sizeof(NSString *), log(sizeof(NSString *)), "i"); | |
objc_property_attribute_t type = {"T", "@\"NSString\""}; | |
objc_property_attribute_t ownership = { "C", "" }; | |
objc_property_attribute_t backingivar = { "V", "_ivar1"}; | |
objc_property_attribute_t attrs[] = {type, ownership, backingivar}; | |
class_addProperty(cls, "property2", attrs, 3); | |
objc_registerClassPair(cls); | |
id instance = [[cls alloc] init]; | |
[instance performSelector:@selector(submethod1)]; | |
[instance performSelector:@selector(method1)]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment