Skip to content

Instantly share code, notes, and snippets.

@efremidze
Last active March 12, 2017 01:12
Show Gist options
  • Save efremidze/ca2716a57980202eea61af07794c5e56 to your computer and use it in GitHub Desktop.
Save efremidze/ca2716a57980202eea61af07794c5e56 to your computer and use it in GitHub Desktop.
List of class's properties
func propertyNames(forClass: AnyClass) -> [String] {
var count = UInt32()
let properties = class_copyPropertyList(forClass, &count)
let names: [String] = (0..<Int(count)).flatMap { i in
let property: objc_property_t = properties[i]
guard let name = NSString(UTF8String: property_getName(property)) as? String else {
debugPrint("Couldn't unwrap property name for \(property)")
return nil
}
return name
}
free(properties)
return names
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment