krakendev / predikit Goto Github PK
View Code? Open in Web Editor NEWAn NSPredicate DSL for iOS, OSX, tvOS, & watchOS. Inspired by SnapKit and lovingly written in Swift.
License: MIT License
An NSPredicate DSL for iOS, OSX, tvOS, & watchOS. Inspired by SnapKit and lovingly written in Swift.
License: MIT License
Let's say I have the following code:
let predicate = NSPredicate(Shipment.self) { includeIf in
let includeIfState = includeIf.member(Selector(ShipmentRelationships.currentState.rawValue), ofType: State.self).string(Selector(StateAttributes.stateRaw.rawValue))
let noOffer = includeIf.member(Selector(ShipmentRelationships.acceptedOffer.rawValue), ofType: Offer.self).equalsNil
let cancelled = includeIfState.equals(State.State.Cancelled.rawValue)
let expired = includeIf.number(Selector(ShipmentAttributes.pickupTimeTo.rawValue)).isLessThanOrEqualTo(soon)
let sender = includeIf.member(Selector(ShipmentRelationships.sender.rawValue), ofType: Sender.self).equals(data)
sender && noOffer && !cancelled && !expired
}
Unexpectedly, the resulting predicate is something like this:
sender == 1464553718.353965 AND acceptedOffer == nil AND (NOT currentState.stateRaw == "cancelled") AND (NOT pickupTimeTo <= <Sender: 0x7fe2cb708720> (entity: Sender; id: 0xd000000000080000 x-coredata://F5039107-C745-4046-B0B5-5F71ED5738B7/Sender/p2 ; data: {...}))
As you can see, the parameters of the sender
and expired
sub-predicates have been exchanged.
Side note: I'm using variables inside the block because this is a simplified example. In the actual code, the final predicate is composed of different sub-predicates depending on some filter parameter.
I used PrediKit
in two projects installed through CocoaPods
.
In my new one I used Carthage
and now XCode
throws an error: Module file's minimum deployment target is ios8.3 v8.3: .../Carthage/Build/iOS/PrediKit.framework/Modules/PrediKit.swiftmodule/i386.swiftmodule
What I'm doing wrong or did in my previous two projects?
Hello,
I installed it, and while running it in Swift 4.2, I keep getting the following error. I get it on both MemberQuery.swift and PredicateBuilder.swift
/Pods/PrediKit/Sources/Queries/MemberQuery.swift:48:26: Cannot invoke initializer for type 'String' with an argument list of type '(T.Type)'
Please Help!
Case where we want to query an object with related objects, such as:
class Captain: NSObject {
var name: String
}
class Ship: NSObject {
var captain: Captain
}
NSPredicate(format: "captain == %@", someCaptain)
NSPredicate(format: "captain.name == 'Chief Supreme'")
There currently is no method to match an object property (example 1), or to match a related object's property (example 2).
Are there currently any plans for this?
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
Just a house keeping issue...since a new release wasn't created when Swift 4 support was added back in May, integrating with CocoaPods requires referencing the master branch or the Swift 4 commit.
In the latest swift migration there are two lies of code in #IF DEBUG blocks that weren't migrated along with the rest. This causes compilation errors when trying to build in debug.
I have the fix done locally for normal development, but it would be nice to fix for first pod installs and the like.
The problems are in MemberQuery.swift on line 48 and PredicateBuilder.swift on line 150. Both require changing String(type)
to String(describing: type)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.