Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ncreated/dedd8f8b628fbb820b0771e8355e32b9 to your computer and use it in GitHub Desktop.
Save ncreated/dedd8f8b628fbb820b0771e8355e32b9 to your computer and use it in GitHub Desktop.
Inspect NSObject private properties and methods
extension NSObject {
var __methods: [Selector] {
var methodCount: UInt32 = 0
guard
let methodList = class_copyMethodList(type(of: self), &methodCount),
methodCount != 0
else { return [] }
return (0 ..< Int(methodCount))
.compactMap({ method_getName(methodList[$0]) })
}
var __properties: Any {
var propertiesCount: UInt32 = 0
guard
let propertiesList = class_copyPropertyList(type(of: self), &propertiesCount),
propertiesCount != 0
else { return [] }
return (0 ..< Int(propertiesCount))
.compactMap({ property_getName(propertiesList[$0]) })
.map({ NSString(cString: $0, encoding: NSUTF8StringEncoding) })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment