// 修改isa,本质就是改变当前对象的类名
object_setClass(self, [XMGKVONotifying_Person class]);
// self动态添加关联
// id object:给哪个对象添加关联属性
// key:属性名
// value:关联值
//objc_setAssociatedObject(id object, const void *key, id value, objc_AssociationPolicy policy)
objc_setAssociatedObject(self, @"observer", observer, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
// self获取关联
//objc_getAssociatedObject(id object, const void *key)
id observer = objc_getAssociatedObject(self, @"observer");
运行时c函数
时间: 2024-10-09 03:22:50