Created
November 24, 2014 20:31
-
-
Save loganwright/92279d97a947469833f6 to your computer and use it in GitHub Desktop.
Get properties from a swift object -- NSObject extension
This file contains 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
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