UIKit框架之NSObject

简介:

首先学习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





相关文章
|
Swift
Swift - UIView,UILabel,UIButton,UIImageView
Swift - UIView,UILabel,UIButton,UIImageView
100 0
|
iOS开发
NSObject类了解
今天看一本书,偶然间看到关于继承的那一章。上面有一句话是这么说的:在OC中,允许定义自己的根类,但通常不这么做,而是希望利用现有的类。因此,我们所定义的类都是属于NSObject根类的派生类。
977 0
|
iOS开发 MacOS 开发者
UIViewController/ApplicationSequ…
UIViewController   ApplicationSequence UI-03 注意: NSLog(@"%s %d",__FUNCTION__,__LINE__); //打印程序方法的执行过程,    //__FUNCTION__,执行的方法名;__LINE__ 显示的NSlL...
754 0
|
开发者
UIViewController
UIViewController在UIKit中主要功能是用于控制画面的切换,其中的view属性(UIView类型)管理整个画面的外观.大部分控制器类都会继承UIKit的UIViewController基类,该基类中包含了大量方法,可以重写这些方法来处理视图的加载、视图显示等各种事件。
744 0
|
API 索引 Windows
UIView相关方法
<p style="margin:10px auto; padding-top:0px; padding-bottom:0px; line-height:19px; font-size:13px; font-family:Verdana,Arial,Helvetica,sans-serif"> <span style="margin:0px; padding:0px; line-heig
1305 0