Created
March 2, 2023 10:19
-
-
Save ncreated/dedd8f8b628fbb820b0771e8355e32b9 to your computer and use it in GitHub Desktop.
Inspect NSObject private properties and methods
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
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