/* NSObject.h
Copyright (c) 1994-2012, Apple Inc. All rights reserved.
*/
#import <Foundation/NSObjCRuntime.h> 大量宏定义
#import <Foundation/NSZone.h> 内存分配和释放的优化方式
@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
NSInvocation:消息转发 NSMethodSignature : 该对象负责封装与方法参数和返回值有关系的信息 NSCoder :对象编码和解码 NSString:字符串处理 NSEnumerator.h:集合抽象类
@class Protocol; 协议
/*************** Basic protocols ***************/ 协议定义部分
@protocol NSObject
- (BOOL)isEqual:(id)object; 首先判断两个对象是否类型一致, 再判断具体内容是否一致
- (NSUInteger)hash; 返回一个整数,可以用来作为哈希表结构中的表地址
- (Class)superclass; 返回超类对象
- (Class)class; 返回类对象
- (id)self; 返回当前对象
- (NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 垃圾自动回收
- (id)performSelector:(SEL)aSelector; 将指定的消息配送到接收器,应用aSelector指定的消息
- (id)performSelector:(SEL)aSelector withObject:(id)object; 将对象消息配送到接收器,应用aSelector指定的消息
- (id)performSelector:(SEL)aSelector withObject:(id)object1 withObject:(id)object2; 将2个对象消息配送到接收器,应用aSelector指定的消息
- (BOOL)isProxy;判断是否接收器是否从NSObject继承
- (BOOL)isKindOfClass:(Class)aClass; 判断是否是这个类或者这个类的子类的实例
- (BOOL)isMemberOfClass:(Class)aClass; 判断是否是这个类的实例
- (BOOL)conformsToProtocol:(Protocol *)aProtocol; 判断是否符合协议
- (BOOL)respondsToSelector:(SEL)aSelector; 判断是否实现了某方法
- (id)retain NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 增加对象的计数器
- (oneway void)release NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 减少对象的计数器
- (id)autorelease NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 自动减少对象的计数器,但是以推迟的方式来实现
- (NSUInteger)retainCount NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 返回一个对象当前的计数器
- (NSString *)description; 允许一个对象返回一个字符串来描述它的内容;这个常用于调试debugging (“print object”命令 )
@optional
- (NSString *)debugDescription; 返回一个字符串,描述在调试器中的接收器演示的内容
@end
@protocol NSCopying
- (id)copyWithZone:(NSZone *)zone; 复制任意对象的内存
@end
@protocol NSMutableCopying
- (id)mutableCopyWithZone:(NSZone *)zone; 该类来完成易变的对象拷贝
@end
@protocol NSCoding
- (void)encodeWithCoder:(NSCoder *)aCoder; 允许对象编译它的实例变量
- (id)initWithCoder:(NSCoder *)aDecoder; 允许一个对象初始化它自身的解码实例变量
@end
// Objects which are safe to be encoded and decoded across privilege boundaries should adopt NSSecureCoding instead of NSCoding. Secure coders (those that respond YES to requiresSecureCoding) will only encode objects that adopt the NSSecureCoding protocol.
@protocol NSSecureCoding <NSCoding>
@required
// This method must be return YES on all classes that allow secure coding. Subclasses of classes that adopt NSSecureCoding and override initWithCoder: must also override this method and return YES.
// The Secure Coding Guide should be consulted when writing methods that decode data.
+ (BOOL)supportsSecureCoding;
@end
/*********** Base class ***********/
NS_ROOT_CLASS
@interface NSObject <NSObject> {
Class isa;
}
+ (void)load; 初始化加载
+ (void)initialize; 初始化对象
- (id)init; 初始化对象,分配内存
+ (id)new; 分配一个新的接收类实例,并将它发送一个init消息,并返回初始化的对象。
+ (id)allocWithZone:(NSZone *)zone; 在内存中为一个对象分配了内存空间并且设置它指向的对象的编译器类定义,返回该实例。
+ (id)alloc; 在内存中为一个对象分配了内存空间并且设置它指向的对象的编译器类定义,返回该实例。
- (void)dealloc; 应用于类来释放对象实例变量并释放动态内存
- (void)finalize;在垃圾收集器运行期间进行一些特殊的工作.
- (id)copy; 复制任意对象的内存
- (id)mutableCopy; 复制易变的对象
+ (id)copyWithZone:(NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 复制任意对象的内存,深复制, 标记自动内存释放是否可用
+ (id)mutableCopyWithZone:(NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 复制易变的对象 标记自动内存释放是否可用
+ (Class)superclass; 返回超类对象
+ (Class)class;返回类对象
+ (BOOL)instancesRespondToSelector:(SEL)aSelector; 测试了一个给定的类实例化之后, 是否实现了一个指定的方法
+ (BOOL)conformsToProtocol:(Protocol *)protocol; 测试接收器(对象或者类)符合一个给定的协议(protocol)
- (IMP)methodForSelector:(SEL)aSelector; 一个 获取指向方法实现IMP 的指针
+ (IMP)instanceMethodForSelector:(SEL)aSelector; 返回的实施地址选择器
- (void)doesNotRecognizeSelector:(SEL)aSelector; 处理消息接收
- (id)forwardingTargetForSelector:(SEL)aSelector NS_AVAILABLE(10_5, 2_0); 转发消息
- (void)forwardInvocation:(NSInvocation *)anInvocation; 允许一个对象把消息转发给另一个对象
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector; 判断消息fun是否有效注册
+ (NSMethodSignature *)instanceMethodSignatureForSelector:(SEL)aSelector;获得类和方法的签名
- (BOOL)allowsWeakReference NS_UNAVAILABLE; 允许弱参考引用标量
- (BOOL)retainWeakReference NS_UNAVAILABLE; 保留弱参照变量
+ (NSString *)description; 允许一个对象返回一个字符串来描述它的内容;这个常用于调试debugging (“print object”命令 )
+ (BOOL)isSubclassOfClass:(Class)aClass; 判断对象是否是指定类的子类
+ (BOOL)resolveClassMethod:(SEL)sel NS_AVAILABLE(10_5, 2_0); 动态方法解析
+ (BOOL)resolveInstanceMethod:(SEL)sel NS_AVAILABLE(10_5, 2_0); 动态方法解析
@end
@interface NSObject (NSCoderMethods)
+ (NSInteger)version; 返回一个版本号
+ (void)setVersion:(NSInteger)aVersion; 设置版本号
- (Class)classForCoder; 对象编码
- (id)replacementObjectForCoder:(NSCoder *)aCoder; 对象编码
- (id)awakeAfterUsingCoder:(NSCoder *)aDecoder NS_REPLACES_RECEIVER; 对象编码
@end
#if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
@interface NSObject (NSDeprecatedMethods)
+ (void)poseAsClass:(Class)aClass NS_DEPRECATED(10_0, 10_5, 2_0, 2_0) 构造指定父类
#if __OBJC2__
UNAVAILABLE_ATTRIBUTE
#endif
;
@end
#endif
/*********** Discardable Content ***********/
@protocol NSDiscardableContent 计数为0,可丢弃协议,
@required
- (BOOL)beginContentAccess; 如果舍弃内容可用,返回YES
- (void)endContentAccess; 丢掉不可用的内容
- (void)discardContentIfPossible; 处理计数为0的内容
- (BOOL)isContentDiscarded; 判断内容是否被丢弃
@end
@interface NSObject (NSDiscardableContentProxy) //可丢弃代理类别
- (id)autoContentAccessingProxy NS_AVAILABLE(10_6, 4_0);
@end
/*********** Object Allocation / Deallocation *******/ 内存分配
FOUNDATION_EXPORT id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone) NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 负责的obj-C对象分配内存
FOUNDATION_EXPORT void NSDeallocateObject(id object) NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 重新分配对象内存
FOUNDATION_EXPORT id NSCopyObject(id object, NSUInteger extraBytes, NSZone *zone) NS_AUTOMATED_REFCOUNT_UNAVAILABLE NS_DEPRECATED(10_0, 10_8, 2_0, 6_0); 返回对象的精确副本,深复制
FOUNDATION_EXPORT BOOL NSShouldRetainWithZone(id anObject, NSZone *requestedZone) NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 如果请求内存地址成功,返回YES,否则NO
FOUNDATION_EXPORT void NSIncrementExtraRefCount(id object) NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 增加额外的引用计数
FOUNDATION_EXPORT BOOL NSDecrementExtraRefCountWasZero(id object) NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 如果引用计数为0,返回YES,否则NO
FOUNDATION_EXPORT NSUInteger NSExtraRefCount(id object) NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 返回引用计数数
#if __has_feature(objc_arc)
// After using a CFBridgingRetain on an NSObject, the caller must take responsibility for calling CFRelease at an appropriate time. //使用CFBridgingRetain。则需要自己手动释放(CFRelease)
NS_INLINE CF_RETURNS_RETAINED CFTypeRef CFBridgingRetain(id X) { //增加引用计数
return (__bridge_retained CFTypeRef)X;
}
NS_INLINE id CFBridgingRelease(CFTypeRef CF_CONSUMED X) { //减少引用计数
return (__bridge_transfer id)X;
}
#else
// This function is intended for use while converting to ARC mode only. //转换为ARC模式,系统自动处理添加,和释放引用计数
NS_INLINE CF_RETURNS_RETAINED CFTypeRef CFBridgingRetain(id X) { //增加引用计数
return X ? CFRetain((CFTypeRef)X) : NULL;
}
// This function is intended for use while converting to ARC mode only.
NS_INLINE id CFBridgingRelease(CFTypeRef CF_CONSUMED X) { //减少引用计数
return [(id)CFMakeCollectable(X) autorelease];
}
#endif
Copyright (c) 1994-2012, Apple Inc. All rights reserved.
*/
#import <Foundation/NSObjCRuntime.h> 大量宏定义
#import <Foundation/NSZone.h> 内存分配和释放的优化方式
@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
NSInvocation:消息转发 NSMethodSignature : 该对象负责封装与方法参数和返回值有关系的信息 NSCoder :对象编码和解码 NSString:字符串处理 NSEnumerator.h:集合抽象类
@class Protocol; 协议
/*************** Basic protocols ***************/ 协议定义部分
@protocol NSObject
- (BOOL)isEqual:(id)object; 首先判断两个对象是否类型一致, 再判断具体内容是否一致
- (NSUInteger)hash; 返回一个整数,可以用来作为哈希表结构中的表地址
- (Class)superclass; 返回超类对象
- (Class)class; 返回类对象
- (id)self; 返回当前对象
- (NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 垃圾自动回收
- (id)performSelector:(SEL)aSelector; 将指定的消息配送到接收器,应用aSelector指定的消息
- (id)performSelector:(SEL)aSelector withObject:(id)object; 将对象消息配送到接收器,应用aSelector指定的消息
- (id)performSelector:(SEL)aSelector withObject:(id)object1 withObject:(id)object2; 将2个对象消息配送到接收器,应用aSelector指定的消息
- (BOOL)isProxy;判断是否接收器是否从NSObject继承
- (BOOL)isKindOfClass:(Class)aClass; 判断是否是这个类或者这个类的子类的实例
- (BOOL)isMemberOfClass:(Class)aClass; 判断是否是这个类的实例
- (BOOL)conformsToProtocol:(Protocol *)aProtocol; 判断是否符合协议
- (BOOL)respondsToSelector:(SEL)aSelector; 判断是否实现了某方法
- (id)retain NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 增加对象的计数器
- (oneway void)release NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 减少对象的计数器
- (id)autorelease NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 自动减少对象的计数器,但是以推迟的方式来实现
- (NSUInteger)retainCount NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 返回一个对象当前的计数器
- (NSString *)description; 允许一个对象返回一个字符串来描述它的内容;这个常用于调试debugging (“print object”命令 )
@optional
- (NSString *)debugDescription; 返回一个字符串,描述在调试器中的接收器演示的内容
@end
@protocol NSCopying
- (id)copyWithZone:(NSZone *)zone; 复制任意对象的内存
@end
@protocol NSMutableCopying
- (id)mutableCopyWithZone:(NSZone *)zone; 该类来完成易变的对象拷贝
@end
@protocol NSCoding
- (void)encodeWithCoder:(NSCoder *)aCoder; 允许对象编译它的实例变量
- (id)initWithCoder:(NSCoder *)aDecoder; 允许一个对象初始化它自身的解码实例变量
@end
// Objects which are safe to be encoded and decoded across privilege boundaries should adopt NSSecureCoding instead of NSCoding. Secure coders (those that respond YES to requiresSecureCoding) will only encode objects that adopt the NSSecureCoding protocol.
@protocol NSSecureCoding <NSCoding>
@required
// This method must be return YES on all classes that allow secure coding. Subclasses of classes that adopt NSSecureCoding and override initWithCoder: must also override this method and return YES.
// The Secure Coding Guide should be consulted when writing methods that decode data.
+ (BOOL)supportsSecureCoding;
@end
/*********** Base class ***********/
NS_ROOT_CLASS
@interface NSObject <NSObject> {
Class isa;
}
+ (void)load; 初始化加载
+ (void)initialize; 初始化对象
- (id)init; 初始化对象,分配内存
+ (id)new; 分配一个新的接收类实例,并将它发送一个init消息,并返回初始化的对象。
+ (id)allocWithZone:(NSZone *)zone; 在内存中为一个对象分配了内存空间并且设置它指向的对象的编译器类定义,返回该实例。
+ (id)alloc; 在内存中为一个对象分配了内存空间并且设置它指向的对象的编译器类定义,返回该实例。
- (void)dealloc; 应用于类来释放对象实例变量并释放动态内存
- (void)finalize;在垃圾收集器运行期间进行一些特殊的工作.
- (id)copy; 复制任意对象的内存
- (id)mutableCopy; 复制易变的对象
+ (id)copyWithZone:(NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 复制任意对象的内存,深复制, 标记自动内存释放是否可用
+ (id)mutableCopyWithZone:(NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 复制易变的对象 标记自动内存释放是否可用
+ (Class)superclass; 返回超类对象
+ (Class)class;返回类对象
+ (BOOL)instancesRespondToSelector:(SEL)aSelector; 测试了一个给定的类实例化之后, 是否实现了一个指定的方法
+ (BOOL)conformsToProtocol:(Protocol *)protocol; 测试接收器(对象或者类)符合一个给定的协议(protocol)
- (IMP)methodForSelector:(SEL)aSelector; 一个 获取指向方法实现IMP 的指针
+ (IMP)instanceMethodForSelector:(SEL)aSelector; 返回的实施地址选择器
- (void)doesNotRecognizeSelector:(SEL)aSelector; 处理消息接收
- (id)forwardingTargetForSelector:(SEL)aSelector NS_AVAILABLE(10_5, 2_0); 转发消息
- (void)forwardInvocation:(NSInvocation *)anInvocation; 允许一个对象把消息转发给另一个对象
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector; 判断消息fun是否有效注册
+ (NSMethodSignature *)instanceMethodSignatureForSelector:(SEL)aSelector;获得类和方法的签名
- (BOOL)allowsWeakReference NS_UNAVAILABLE; 允许弱参考引用标量
- (BOOL)retainWeakReference NS_UNAVAILABLE; 保留弱参照变量
+ (NSString *)description; 允许一个对象返回一个字符串来描述它的内容;这个常用于调试debugging (“print object”命令 )
+ (BOOL)isSubclassOfClass:(Class)aClass; 判断对象是否是指定类的子类
+ (BOOL)resolveClassMethod:(SEL)sel NS_AVAILABLE(10_5, 2_0); 动态方法解析
+ (BOOL)resolveInstanceMethod:(SEL)sel NS_AVAILABLE(10_5, 2_0); 动态方法解析
@end
@interface NSObject (NSCoderMethods)
+ (NSInteger)version; 返回一个版本号
+ (void)setVersion:(NSInteger)aVersion; 设置版本号
- (Class)classForCoder; 对象编码
- (id)replacementObjectForCoder:(NSCoder *)aCoder; 对象编码
- (id)awakeAfterUsingCoder:(NSCoder *)aDecoder NS_REPLACES_RECEIVER; 对象编码
@end
#if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
@interface NSObject (NSDeprecatedMethods)
+ (void)poseAsClass:(Class)aClass NS_DEPRECATED(10_0, 10_5, 2_0, 2_0) 构造指定父类
#if __OBJC2__
UNAVAILABLE_ATTRIBUTE
#endif
;
@end
#endif
/*********** Discardable Content ***********/
@protocol NSDiscardableContent 计数为0,可丢弃协议,
@required
- (BOOL)beginContentAccess; 如果舍弃内容可用,返回YES
- (void)endContentAccess; 丢掉不可用的内容
- (void)discardContentIfPossible; 处理计数为0的内容
- (BOOL)isContentDiscarded; 判断内容是否被丢弃
@end
@interface NSObject (NSDiscardableContentProxy) //可丢弃代理类别
- (id)autoContentAccessingProxy NS_AVAILABLE(10_6, 4_0);
@end
/*********** Object Allocation / Deallocation *******/ 内存分配
FOUNDATION_EXPORT id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone) NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 负责的obj-C对象分配内存
FOUNDATION_EXPORT void NSDeallocateObject(id object) NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 重新分配对象内存
FOUNDATION_EXPORT id NSCopyObject(id object, NSUInteger extraBytes, NSZone *zone) NS_AUTOMATED_REFCOUNT_UNAVAILABLE NS_DEPRECATED(10_0, 10_8, 2_0, 6_0); 返回对象的精确副本,深复制
FOUNDATION_EXPORT BOOL NSShouldRetainWithZone(id anObject, NSZone *requestedZone) NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 如果请求内存地址成功,返回YES,否则NO
FOUNDATION_EXPORT void NSIncrementExtraRefCount(id object) NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 增加额外的引用计数
FOUNDATION_EXPORT BOOL NSDecrementExtraRefCountWasZero(id object) NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 如果引用计数为0,返回YES,否则NO
FOUNDATION_EXPORT NSUInteger NSExtraRefCount(id object) NS_AUTOMATED_REFCOUNT_UNAVAILABLE; 返回引用计数数
#if __has_feature(objc_arc)
// After using a CFBridgingRetain on an NSObject, the caller must take responsibility for calling CFRelease at an appropriate time. //使用CFBridgingRetain。则需要自己手动释放(CFRelease)
NS_INLINE CF_RETURNS_RETAINED CFTypeRef CFBridgingRetain(id X) { //增加引用计数
return (__bridge_retained CFTypeRef)X;
}
NS_INLINE id CFBridgingRelease(CFTypeRef CF_CONSUMED X) { //减少引用计数
return (__bridge_transfer id)X;
}
#else
// This function is intended for use while converting to ARC mode only. //转换为ARC模式,系统自动处理添加,和释放引用计数
NS_INLINE CF_RETURNS_RETAINED CFTypeRef CFBridgingRetain(id X) { //增加引用计数
return X ? CFRetain((CFTypeRef)X) : NULL;
}
// This function is intended for use while converting to ARC mode only.
NS_INLINE id CFBridgingRelease(CFTypeRef CF_CONSUMED X) { //减少引用计数
return [(id)CFMakeCollectable(X) autorelease];
}
#endif