Objective-C Runtime整理(分类和协议)

基础数据类型

Category

typedef struct objc_category *Category;

struct objc_category {
    char *category_name  OBJC2_UNAVAILABLE; // 分类名

    char *class_name  OBJC2_UNAVAILABLE; // 分类所属的类名

    struct objc_method_list *instance_methods  OBJC2_UNAVAILABLE; // 实例方法列表

    struct objc_method_list *class_methods  OBJC2_UNAVAILABLE; // 类方法列表

    struct objc_protocol_list *protocols  OBJC2_UNAVAILABLE; // 分类所实现的协议列表
}

Protocol

typedef struct objc_object Protocol;

操作方法

类相关

// 返回指定的协议

Protocol * objc_getProtocol ( const char *name );

// 获取运行时所知道的所有协议的数组

Protocol ** objc_copyProtocolList ( unsigned int *outCount );

// 创建新的协议实例

Protocol * objc_allocateProtocol ( const char *name );

// 在运行时中注册新创建的协议

void objc_registerProtocol ( Protocol *proto );

protocol相关

// 为协议添加方法

void protocol_addMethodDescription ( Protocol *proto, SEL name, const char *types, BOOL isRequiredMethod, BOOL isInstanceMethod );

// 添加一个已注册的协议到协议中

void protocol_addProtocol ( Protocol *proto, Protocol *addition );

// 为协议添加属性

void protocol_addProperty ( Protocol *proto, const char *name, const objc_property_attribute_t *attributes, unsigned int attributeCount, BOOL isRequiredProperty, BOOL isInstanceProperty );

// 返回协议名

const char * protocol_getName ( Protocol *p );

// 测试两个协议是否相等

BOOL protocol_isEqual ( Protocol *proto, Protocol *other );

// 获取协议中指定条件的方法的方法描述数组

struct objc_method_description * protocol_copyMethodDescriptionList ( Protocol *p, BOOL isRequiredMethod, BOOL isInstanceMethod, unsigned int *outCount );

// 获取协议中指定方法的方法描述

struct objc_method_description protocol_getMethodDescription ( Protocol *p, SEL aSel, BOOL isRequiredMethod, BOOL isInstanceMethod );

// 获取协议中的属性列表

objc_property_t * protocol_copyPropertyList ( Protocol *proto, unsigned int *outCount );

// 获取协议的指定属性

objc_property_t protocol_getProperty ( Protocol *proto, const char *name, BOOL isRequiredProperty, BOOL isInstanceProperty );

// 获取协议采用的协议

Protocol ** protocol_copyProtocolList ( Protocol *proto, unsigned int *outCount );

// 查看协议是否采用了另一个协议

BOOL protocol_conformsToProtocol ( Protocol *proto, Protocol *other );
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值