首先学习NSObject
// // ViewController.m // localization // // Created by City--Online on 15/5/15. // Copyright (c) 2015年 XQB. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //NSObject内包含 alloc、init方法 NSObject *obj=[[NSObject alloc]init]; //父类 NSLog(@"superClass: %@",[obj superclass]); //当前类 NSLog(@"Class: %@",[obj class]); //copy NSLog(@"copy: %@",[NSObject copy]); //hash NSLog(@"hash:%ld",[obj hash]); //description NSLog(@"description: %@",[obj description]); //debugDescription NSLog(@"debugDescription: %@",[obj debugDescription]); // - (id)performSelector:(SEL)aSelector; // - (id)performSelector:(SEL)aSelector withObject:(id)object; // - (id)performSelector:(SEL)aSelector withObject:(id)object1 withObject:(id)object2; [self performSelector:@selector(test)]; //isProxy BOOL isProxy=[obj isProxy]; NSLog(@"isProxy: %d",isProxy); // - (BOOL)isKindOfClass:(Class)aClass; // - (BOOL)isMemberOfClass:(Class)aClass; // - (BOOL)conformsToProtocol:(Protocol *)aProtocol; // - (BOOL)respondsToSelector:(SEL)aSelector; //来确定一个对象是否是一个类的成员,或者是派生自该类的成员 BOOL isKindOfClass=[obj isKindOfClass:[NSObject class]]; NSLog(@"isKindOfClass:%d",isKindOfClass); //只能确定一个对象是否是当前类的成员 BOOL isMemberOfClass=[obj isMemberOfClass:[NSObject class]]; NSLog(@"isMemberOfClass:%d",isMemberOfClass); //是用来检查对象是否实现了指定协议类的方法 BOOL IsConformsToProtocol=[obj conformsToProtocol:@protocol(UIApplicationDelegate)]; NSLog(@"IsConformsToProtocol: %d",IsConformsToProtocol); //用来判断是否有以某个名字命名的方法(被封装在一个selector的对象里传递) BOOL isRespondsToSelector=[obj respondsToSelector:@selector(hash)]; NSLog(@"isRespondsToSelector:%d",isRespondsToSelector); // selector 用来判断实例是否有以某个名字命名的方法. 和上面一个不同之处在于, 前面这个方法可以用在实例和类上,而此方法只能用在类上 BOOL isInstancesRespondToSelector=[NSObject instancesRespondToSelector:@selector(hash)]; NSLog(@"isInstancesRespondToSelector:%d",isInstancesRespondToSelector); } -(void)test { NSLog(@"test"); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end