CocoaChina中找到了一段OC中遍历所有属性的代码
int i;
int propertyCount = 0;
objc_property_t *propertyList = class_copyPropertyList([aPerson class], &propertyCount);
for ( i=0; i < propertyCount; i++ ) {
objc_property_t *thisProperty = propertyList + i;
const char* propertyName = property_getName(*thisProperty);
NSLog(@"Person has a property: '%s'", propertyName);
}
但是试了试似乎没法直接改写成Swift,propertyList那里得到的是UnsafeMutablePointer(nil)……
求正确的改写方式或者遍历方法……
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
ringa_lee