NSObject学习

来源:互联网 发布:贪吃蛇大作战h5源码 编辑:程序博客网 时间:2024/06/07 08:28
    1. - (id)copy //Returns the object returned by copyWithZone:.调用copyWithZone方法实现复制功能,若是自己的类

               //则需要实现copyWithZone方法

    1. 如:NSString *str2 = [str1 copy];
    1.  + (id)copyWithZone:(struct _NSZone *)zone//copy方法的实现者
      1. -(id)copyWithZone:(NSZone *)zone

    {

    Engine * engineCopy;

    copyWithZone = [[[self class]allocWithZone:zone]init];

    Return(engineCopy)

    }   

    1. - (id)mutableCopy//copy,这里获得的是可变的对象
      1. 如:NSMutableString  * mutableStr1= [str1 mutableCopy];
    2. + (id)mutableCopyWithZone:(struct _NSZone *)zone//不关注
    3. + (Class)class//Returns the class object. 返回类对象
      1. BOOLtest= [selfisKindOfClass:[SomeClassclass]];
    1. + (Class)superclass//Returns the class object for the receiver’s superclass.返回父类的类对象
    2. +(BOOL)isSubclassOfClass:(Class)aClass//判断消息接收者所属的类是不是aClass的子类
    3. + (BOOL)instancesRespondToSelector:(SEL)aSelector//判断对象能否相应给定的选择器(方法)
    4. + (BOOL)conformsToProtocol:(Protocol *)aProtocol//判断对象是否实现给定的协议
    5. ……
    6. + (NSString *)description//描述
    1. - (void)performSelector:(SEL)aSelectorwithObject:(id)anArgumentafterDelay:(NSTimeInterval)delay
      1. Invokes a method of the receiver on the current thread using the default mode after a delay.
    2. - (BOOL)isKindOfClass:(Class)aClass
      1. Returns a Boolean value that indicates whether the receiver is an instance of given class or an instance of any class that inherits from that class. (required)
    3. - (BOOL)isMemberOfClass:(Class)aClass
      1. Returns a Boolean value that indicates whether the receiver is an instance of a given class. (required)
      2. 是不是给定类的子类
    1. - (BOOL)respondsToSelector:(SEL)aSelector
      1. Returns a Boolean value that indicates whether the receiver implements or inherits a method that can respond to a specified message. (required)
    2. - (BOOL)conformsToProtocol:(Protocol *)aProtocol
      1. Returns a Boolean value that indicates whether the receiver conforms to a given protocol. (required)
    3. - (id)performSelector:(SEL)aSelector
      1. Sends a specified message to the receiver and returns the result of the message. (required)
    4. - (id)performSelector:(SEL)aSelectorwithObject:(id)anObject//同上,object是传入的参数可为nil
    5. ……

     

     

0 0
原创粉丝点击