Skip to content

Instantly share code, notes, and snippets.

@loganwright
Created November 24, 2014 20:31
Show Gist options
  • Save loganwright/92279d97a947469833f6 to your computer and use it in GitHub Desktop.
Save loganwright/92279d97a947469833f6 to your computer and use it in GitHub Desktop.
Get properties from a swift object -- NSObject extension
extension NSObject {
class var propertyNames: [String] {
get {
var count: UInt32 = 0
let properties: UnsafeMutablePointer<objc_property_t> = class_copyPropertyList(self.classForCoder(), &count)
var propertyNames: [String] = []
for i in 0..<count {
let property: objc_property_t = properties[Int(i)]
if let name = String(UTF8String: property_getName(property)) {
propertyNames += [name]
}
}
return propertyNames
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment