zoukankan      html  css  js  c++  java
  • objc/runtime.h 相关

    Objecitve-C的重要特性是Runtime(运行时),在Interacting with the Runtime(交互运行)中,运行时函数部分,苹果给出了/usr/lib/libobjc.A.dylib库,这个共享库提供支持动态属性的objective - c语言,通过其接口,可以用于开发将其他语言运行于Objective-C上的中间层(桥接层),库里的函数定义为纯C语言。

    例如:class_getName

    1. class_getName  
    2. Returns the name of a class.  
    3.   
    4. const char * class_getName(Class cls)  
    5. Parameters  
    6. cls  
    7. class object.  
    8. Return Value  
    9. The name of the class, or the empty string if cls is Nil.  
    10.   
    11. Declared In  
    12. runtime.h  



    这里我们要用库里的函数,干个“坏事”,查看苹果SDK的私有方法。

    第一步:导入头文件

    1. #import <objc/runtime.h>   

    第二步:添加下列代码

     **************实用************

    1. NSString *className = NSStringFromClass([UIView class]);  
    2.   
    3.       
    4.     const char *cClassName = [className UTF8String];  
    5.       
    6.     id theClass = objc_getClass(cClassName);  
    7.       
    8.     unsigned int outCount;  
    9.       
    10.   
    11.     Method *m =  class_copyMethodList(theClass,&outCount);  
    12.       
    13.     NSLog(@"%d",outCount);  
    14.     for (int i = 0; i<outCount; i++) {  
    15.         SEL a = method_getName(*(m+i));  
    16.         NSString *sn = NSStringFromSelector(a);  
    17.         NSLog(@"%@",sn);  
    18.     }   

    第三步:想看什么类 就把UIView换成你想要的

    当然,如果只是查看私有API,会有更简单的方法,可以使用工具class-dump,也可以通过此链接,https://github.com/kennytm/iphone-private-frameworks/tree/master/UIKit/    查看。

    特别注意的是,如果是需要上架的APP,切勿使用私有API,会通不过APP Store的审核。

  • 相关阅读:
    ural(Timus) 1346. Intervals of Monotonicity
    SGU 223 Little Kings
    poj 1243 One Person
    poj 1185 炮兵布阵
    poj 1191 棋盘分割
    poj 1187 陨石的秘密
    ACMICPC Live Archive 2451 Brackets Sequence
    将时间格式的字符串转换成日期类型浏览器兼容解决方案
    asp.net项目发布容易忽略的debug=true
    使用微软的Ajax控件遇到的后台js提示语句不起作用的解决方案其一
  • 原文地址:https://www.cnblogs.com/tiechui/p/3819805.html
Copyright © 2011-2022 走看看