设为首页 加入收藏

TOP

浅析iOS Rumtime的机制
2014-11-24 02:48:09 来源: 作者: 【 】 浏览:0
Tags:浅析 iOS Rumtime 机制

学习iOS的同学都知道ojbc一种runtime的语言,runtime表明函数的真正执行的时候来确定函数执行的。这样的好处就是我们能很灵活的设计我们的代码,也能在看似合法的情况下做一些非常有意思的事情,要了解iOS的runtime,我们需要了解iOS的类结构,iOS所有的类的基类都是NSObject这个类,从这个类来分析iOS的runtime机制。


下面我们在xcode 中打开 NSObject 的声明,为了简单明了,我省略了很多,类型和宏的声明。


NS_ROOT_CLASS
@interface NSObject {
Class isa;
}


+ (void)load;


+ (void)initialize;
- (id)init;


+ (id)new;
+ (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;
- (IMP)methodForSelector:(SEL)aSelector;
+ (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;


+ (NSMethodSignature *)instanceMethodSignatureForSelector:(SEL)aSelector;


- (BOOL)allowsWeakReference NS_UNAVAILABLE;
- (BOOL)retainWeakReference NS_UNAVAILABLE;


+ (NSString *)description;


+ (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


推荐阅读:


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android中PreferenceFregment使用.. 下一篇用Shell写的JBoss自动部署脚本

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: