Created
July 10, 2019 14:13
-
-
Save eugenebokhan/2cc06e40b1a4fa53060fa4779297fc78 to your computer and use it in GitHub Desktop.
Get Private 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
import Foundation | |
func getProperties(of object: AnyObject) -> [Any?] { | |
return self.getPropertyNames(of: type(of: object)).map { value(forKey: $0) } | |
} | |
func getPropertyNames(of type: AnyClass) -> [String] { | |
var count: UInt32 = 0 | |
let propertyList = class_copyPropertyList(type, &count) | |
let propertyArray = Array(UnsafeBufferPointer(start: propertyList, count: Int(count))) | |
let propertyNames = propertyArray.map { String(cString: property_getName($0)) } | |
return propertyNames | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment