isKindOfClass
isMemberClass
@implementation Teacher
-(id)init
{
self = [super init];
if (self) {
[self class];// Teacher
[self superclass]; // NSObject
// 这两块,打印输出是一样的?
[super class]; // Teacher
[super superclass];// NSobject
// objc_msgSuper( { self, 父类 } , selector()) ;
}
}
@end
- 这时候要看一下
objc_super
的源代码了-
[super class] [self class]
里class
的方法实现都在NSObject里 -
-(Class)class
的实现,objc_getClass(self)
,返回值取决于self
是谁,取决于消息机制 - 消息接收者仍然子类对象,只不过是从父类里开始查找方法,
objc_msgSuper( { self, 父类 } , selector()) ;
-
struct objc_super {
/// Specifies an instance of a class.
__unsafe_unretained _Nonnull id receiver;
/// Specifies the particular superclass of the instance to message.
#if !defined(__cplusplus) && !__OBJC2__
/* For compatibility with old objc-runtime.h header */
__unsafe_unretained _Nonnull Class class;
#else
__unsafe_unretained _Nonnull Class super_class;
#endif
/* super_class is the first class to search */
};
网友评论