var count : UInt32 = 0 let ivars = class_copyIvarList(UIGestureRecognizer.self,&count)! for i in 0..<count { let ivar = ivars[Int(i)] let name = ivar_getName(ivar) print(String(cString: name!)) }
OC版本的也增加上班
- (NSArray *)filterPropertys { NSMutableArray *props = [NSMutableArray array]; unsigned int outCount,i; objc_property_t *properties = class_copyPropertyList([self class],&outCount); for (i = 0; i<outCount; i++) { objc_property_t property = *properties; const char* char_f =property_getName(property); NSString *propertyName = [NSString stringWithUTF8String:char_f]; NSLog(@"%@",propertyName); } free(properties); return props; }原文链接:https://www.f2er.com/swift/322803.html