Skip to content

Instantly share code, notes, and snippets.

@eugenebokhan
Created July 10, 2019 14:13
Show Gist options
  • Save eugenebokhan/2cc06e40b1a4fa53060fa4779297fc78 to your computer and use it in GitHub Desktop.
Save eugenebokhan/2cc06e40b1a4fa53060fa4779297fc78 to your computer and use it in GitHub Desktop.
Get Private Properties
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