Obj-C库,使运行时自我检查和类修改变得极其简单。
通过使用Objective-C对象封装类的方法和属性,获取类属性的详细信息变得更为简单明了。
从块创建方法并将其添加到类中也非常简单。
轻松获取属性信息
NSArray *properties = [self.klass properties];
for (MYSProperty *property in properties) {
property.type // e.g. MYSTypeLongLong
property.name // e.g. propertyName
property.isReadOnly;
property.storageType; // e.g. MYSPropertyStorageTypeStrong
property.isNonAtomic;
property.getter; // the name of the getter method.
property.setter; // the name of the setter method.
property.isDynamic;
property.isElegibleForGarbageCollection;
property.propertyAttributesString; // the original attributes string.
}
轻松从块创建方法并将其作为方法添加到类中。
MYSMethod *testMethod = [[MYSMethod alloc] initWithName:@"setName:age:"
implementationBlock:^(id self, NSString *name, NSNumber *age)
{
[self setObjectTest:name];
[self setLongTest:[age longValue]];
}];
MYSClass *testClass = [[MYSClass alloc] initWithClass:[MYSTestClass class]];
[testClass addMethod:testMethod];
Adam Kirk @atomkirk