Category-创新互联
Category
当前题目:Category-创新互联
文章起源:http://scyanting.com/article/dicdpc.html
实现原理
我们提供的服务有:成都网站建设、成都网站制作、微信公众号开发、网站优化、网站认证、开平ssl等。为上1000+企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的开平网站制作公司- Category编译之后是一个结构体struct category_t,里边存储着分类的对象方法、类方法、属性、协议信息
- 在程序运行的时候,runtime会将Category的数据,合并到类信息中(类对象,元类对象)
Category和Class Extension的区别
- Class Extension在编译的时候,他的数据就已经包含在类信息中
- Category是在运行时,才会将数据合并到类信息中
Category添加的实例方法是存储在其对应的类对象里,类方法存储在其对应的元类对象里
Category添加的方法是在runtime过程中动态添加的
Category编译完成后结构
多个分类
int mcount = 0;
int i = cats->count; // cats 为分类数组
while (i--) {
auto& entry = cats->list[i];
method_list_t *mlist = entry.cat->methodsFoMeta(isMeta);
mlists[mcount++] = mlist;
// 后编译的分类方法先取出来添加到方法
// ...
}
struct _category_t {
const char *name;
struct _class_t *cls;
const struct _method_list_t *instance_methods;
const struct _method_list_t *class_methods;
const struct _protocol_list_t *protocols;
const struct _prop_list_t *properties;
};
- objc-runtime-old
void attachList(List* const * addedLists, uint32_t addedCount) {
if (addedCount == 0) return;
if (haveArray()) {
uint32_t oldCount = array()->count;
uint32_t newCount = oldCount + addedCount;
setArray((array_t *)realloc(array(), array_t::byteSize(newCount)));
array()->count = newCount;
memmove(array()->lists, addedLists, addedCount * sizeof(array()->lists[0]));
memcopy(array()->lists, addedLists, addedCount * sizeof(array()->lists[0]));
}
}
- objc-runtime-new
void attachLists(List* const * addedLists, uint32_t addedCount) {
if (addedCount == 0) return;
if (hasArray()) {
// many lists ->many lists
uint32_t oldCount = array()->count;
uint32_t newCount = oldCount + addedCount;
array_t *newArray = (array_t *)malloc(array_t::byteSize(newCount));
newArray->count = newCount;
array()->count = newCount;
for (int i = oldCount - 1; i >= 0; i--)
newArray->lists[i + addedCount] = array()->lists[i];
for (unsigned i = 0; i< addedCount; i++)
newArray->lists[i] = addedLists[i];
free(array());
setArray(newArray);
validate();
}
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
当前题目:Category-创新互联
文章起源:http://scyanting.com/article/dicdpc.html