KrakenDev / PrediKit

An NSPredicate DSL for iOS, OSX, tvOS, & watchOS. Inspired by SnapKit and lovingly written in Swift.
MIT License
540 stars 28 forks source link

Remove default implementation Reflectable for NSObject #14

Open kolbasek opened 5 years ago

kolbasek commented 5 years ago

Hi, I use your nice PrediKit to filter realm Results, works pretty good, but needs particular implementation of the properties() method My variant:

extension Object: Reflectable {
    public static func properties() -> [Selector] {
        guard let schema = self.sharedSchema() else { return [] }
        let properties = schema.properties.map {
            Selector($0.name)
        }

        let computedProperties = schema.computedProperties.map {
            Selector($0.name)
        }

        return properties+computedProperties
    }
}

Problem is the following: Object inherited from NSObject, so I can't override your implementation in the NSObject extension

hectormatos2011 commented 5 years ago

Thanks for this! I'll look into it

hectormatos2011 commented 5 years ago

Also feel free to make a PR if you want! For some context, I made the protocol force NSObject conformance because there was no reflection into Swift properties on a class at the time as well as the fact that you aren't allowed to extend AnyObject or Any for Swift objects. Given that we now have keyPaths and Mirror, this may no longer be the case. For now though, I may just make reflectable a base protocol and create a separate objective c protocol that extends it so that way the default implementation for objective c objects don't break.

Would that still work for your project? If so, it's a fairly easy fix and should make for an easy pr. I can do it too when I'm near a computer so whichever works best for you!

kolbasek commented 5 years ago

Sounds cool, I think this will work