objc/runtime.h 相關

Objecitve-C的重要特性是Runtime(運行時),在Interacting with the Runtime(交互運行)中,運行時函數部分,蘋果給出了/usr/lib/libobjc.A.dylib庫,這個共享庫提供支持動態屬性的objective - c語言,經過其接口,能夠用於開發將其餘語言運行於Objective-C上的中間層(橋接層),庫裏的函數定義爲純C語言。git

例如:class_getNamegithub

 

  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的私有方法。app

第一步:導入頭文件iphone

  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換成你想要的oop

 

固然,若是隻是查看私有API,會有更簡單的方法,能夠使用工具class-dump,也能夠經過此連接,https://github.com/kennytm/iphone-private-frameworks/tree/master/UIKit/    查看。spa

特別注意的是,若是是須要上架的APP,切勿使用私有API,會通不過APP Store的審覈。.net

相關文章
相關標籤/搜索