DLIntrospection使用

2018-04-08  本文已影响51人  云无心

DLIntrospection下一共有8个方法

LLDB也能用, 需要注意的是在由于用的运行时, 所以未实现的方法不会出来(.h声明.m未实现) 项目地址
+ (NSArray *)classes; // 打印所有类
+ (NSArray *)properties; // 打印属性
+ (NSArray *)instanceVariables; // 内部变量
+ (NSArray *)classMethods; // 类方法
+ (NSArray *)instanceMethods; // 方法

+ (NSArray *)protocols; // 遵守的协议
+ (NSDictionary *)descriptionForProtocol:(Protocol *)proto; // 自己的协议描述


+ (NSString *)parentClassHierarchy; // 层级关系

下面一个个试吧

打印所有的类, 结果如下 是显示不完的哈哈

+ (NSArray *)classes;
4081E639-0200-4FD0-9F0B-D86C4675599A.png

]

这个方法是打印所有的属性,如下

+ (NSArray *)properties;
FSSSon Properties - (
    "@property (nonatomic, copy) NSString* book",
    "@property (nonatomic, copy) NSString* teacher"
)

打印成员变量

+ (NSArray *)instanceVariables;
FSSFather InstanceVariables - (
    "NSString* _name",
    "NSString* _gender",
    "FSSCar* _car",
    "NSString* _wife"
)

打印类方法

+ (NSArray *)classMethods;
FSSSon ClassMethods - (
    "+ (void)studyClassMethod"
)

打印对象方法

+ (NSArray *)instanceMethods;
FSSFather instanceMethods - (
    "- (void)work",
    "- (id)gender",
    "- (void)setGender:(id)arg0 ",
    "- (id)car",
    "- (id)wife",
    "- (void)setWife:(id)arg0 ",
    "- (void).cxx_destruct",
    "- (id)name",
    "- (void)setName:(id)arg0 ",
    "- (void)setCar:(id)arg0 "
)

注意这里有个 - (void).cxx_destruct 这个方法可以参考 http://blog.jobbole.com/65028/ 这个链接的说明

打印遵守的协议

+ (NSArray *)protocols;
FSSFather protocols (
    "UITableViewDelegate <NSObject, UIScrollViewDelegate>"
)

打印自身协议的关系(可选不可选之类)

+ (NSDictionary *)descriptionForProtocol:(Protocol *)proto;
FSSFather instanceMethods - {
    "@optional" =     (
        "- (void)buyHouseDelegate"
    );
    "@required" =     (
        "- (void)workDelegte"
    );
}

打印层级关系

+ (NSString *)parentClassHierarchy;
FSSFather parentClassHierarchy -  -> FSSFather -> NSObject
上一篇下一篇

猜你喜欢

热点阅读