Dynamic icon indicating copy to clipboard operation
Dynamic copied to clipboard

Logging properties

Open mmackh opened this issue 3 years ago • 2 comments

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
    }
}

mmackh avatar Mar 21 '21 05:03 mmackh

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

polymerchm avatar Mar 22 '21 16:03 polymerchm

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

mmackh avatar Mar 22 '21 17:03 mmackh