/**
1).判断对象是不是指定类的对象或者指定类的子类对象.
- (BOOL)isKindOfClass:(Class)aClass; 2).判断对象是不是1个特定类型的对象,不包括子类.
- (BOOL)isMemberOfClass:(Class)aClass; 3).判断1个类是不是另外1个类的子类.
+ (BOOL)isSubclassOfClass:(Class)aClass; 4).判断对象中是否能响应指定的方法. 这个最常用.
- (BOOL)respondsToSelector:(SEL)aSelector; 5).判断类中是否能响应指定方法.
+(BOOL)instancesRespondToSelector:(SEL)aSelector; */
#import <Foundation/Foundation.h>
#import "DogSon.h" int main(int argc, const char * argv[]) {
@autoreleasepool { // 3).判断1个类是不是另外1个类的子类.
Class c = [Dog class];
BOOL res = [DogSon isSubclassOfClass:c];
NSLog(@"%d",res); }
return ;
}
// 判断 某个类是否能相应制定方法
void demo3(){
SEL s = @selector(play);
BOOL res = [Dog instancesRespondToSelector:s];
NSLog(@"%d",res); }
// 判断某个对象能否相应某个方法
void demo2()
{
Dog *son = [DogSon new]; SEL s = @selector(play); BOOL res = [son respondsToSelector:s]; NSLog(@"%d",res);
}
// 判断对象是不是1个特定类型的对象,不包括子类.不包括父类
void demo1(){
DogSon *son = [DogSon new]; // 获取狗的类对象
Class dog = [Dog class]; // 判断对象是不是1个特定类型的对象,不包括子类.不包括父类
BOOL res = [son isMemberOfClass:dog]; NSLog(@"%d",res);
} // 判断某个对象是否是某个类创建出来的对象
void demo()
{
DogSon *son = [DogSon new]; // 获取小狗的类对象
Class dog = [DogSon class]; //检查son对象是否是小狗类创建出来的对象
BOOL res = [son isKindOfClass:dog]; NSLog(@"%d",res);
}
#import <Foundation/Foundation.h>
#import "Dog.h"
int main(int argc, const char * argv[]) {
@autoreleasepool { Dog *d = [Dog new];
//- (void)run;
[d performSelector:@selector(run)];
//- (void)name:(NSString *)name;
[d performSelector:@selector(name:) withObject:@"哈利"];//方法名是name:,performSelector:withObject:是方法名, }
return ;
}