unsigned int count;
//在运行时创建继承自NSObject的People类
Class People = objc_allocateClassPair([NSObject class], "People", 0);
//完成People类的创建
objc_registerClassPair(People);
objc_property_attribute_t type = {"T", "@\"NSString\""};
objc_property_attribute_t attribute2 = {"N",""};//value无意义时通常设置为空
objc_property_attribute_t ownership = { "C", "" };
objc_property_attribute_t backingivar = { "V", "_pro"};
objc_property_attribute_t attrs[] = {type,attribute2, ownership, backingivar};
//向People类中添加名为pro的属性,属性的4个特性包含在attributes中
BOOL y = class_addProperty(People, "pro", attrs, 4);
NSLog(@"%d",y);
//创建People对象p1
id p1 = [[People alloc]init];
objc_property_t * properties = class_copyPropertyList(People, &count);
for (int i = 0; i<count; i++) {
NSLog(@"属性的名称为 : %s",property_getName(properties[i]));
NSLog(@"属性的特性字符串为: %s",property_getAttributes(properties[i]));
}
//请问怎么为pro赋值?
雷雷
按照你添加的方法, 这个也是可以的
都是大神啊,求教这些语法我从来没学过,我常见的是什么Objective-C 最常用的那种语法。
请问这些语法是属于什么知识呢?在什么地方常用呢?多谢大大解答啊~ 我要掌握这些看着很酷的语法~~~~