mhdhejazi / Dynamic

Call hidden/private API in style! The Swift way.
https://medium.com/@mhdhejazi/calling-ios-and-macos-hidden-api-in-style-1a924f244ad1
Apache License 2.0
695 stars 36 forks source link

Logging properties #12

Open mmackh opened 3 years ago

mmackh commented 3 years ago

thank you for coming up with such a novel way of exploring / calling APIs. When searching for the right API to call, it's sometimes useful to log an object's properties. Is this something you'd consider adding to the framework?

extension NSObject {
    var properties: [String] {
        var count : UInt32 = 0
        let typeOf = type(of: self)
        guard let properties: UnsafeMutablePointer<objc_property_t> = class_copyPropertyList(typeOf, &count) else { return [] }
        var names: [String] = []
        for i in 0..<Int(count) {
            let property : objc_property_t = properties[i]
            guard let name = NSString(utf8String: property_getName(property)) as String? else { continue }
            names.append(name as String)
        }
        free(properties)
        return names
    }
}
polymerchm commented 3 years ago

you can do Dynamic(xxxx).asObject.properties with your extension.

mmackh commented 3 years ago

Yes, I was wondering if this is something that should be added to the framework