Last active
March 12, 2017 01:12
-
-
Save efremidze/ca2716a57980202eea61af07794c5e56 to your computer and use it in GitHub Desktop.
List of class's properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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