diff --git a/CHANGELOG.md b/CHANGELOG.md index 7614781..8001372 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # QueryKit Changelog -## Master +## 0.14.1 ### Bug Fixes diff --git a/Package.swift b/Package.swift index d661163..ebd1d10 100644 --- a/Package.swift +++ b/Package.swift @@ -5,6 +5,7 @@ import PackageDescription let package = Package( name: "QueryKit", products: [ + .library(name: "QueryKit", targets: ["QueryKit"]), ], targets: [ .target(name: "QueryKit", dependencies: []), diff --git a/QueryKit.podspec b/QueryKit.podspec index 9111f55..03c48fd 100644 --- a/QueryKit.podspec +++ b/QueryKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'QueryKit' - spec.version = '0.14.0' + spec.version = '0.14.1' spec.summary = 'A simple type-safe Core Data query language.' spec.homepage = 'https://github.com/QueryKit/QueryKit/' spec.license = { :type => 'BSD', :file => 'LICENSE' } diff --git a/Sources/QueryKit/KeyPath.swift b/Sources/QueryKit/KeyPath.swift index f55733d..8991eaa 100644 --- a/Sources/QueryKit/KeyPath.swift +++ b/Sources/QueryKit/KeyPath.swift @@ -1,5 +1,9 @@ import CoreData +func expression(for keyPath: KeyPath) -> NSExpression { + return NSExpression(forKeyPath: (keyPath as AnyKeyPath)._kvcKeyPathString!) +} + // MARK: Predicate public func == (lhs: KeyPath, rhs: V) -> Predicate { @@ -41,46 +45,37 @@ public func << (lhs: KeyPath, rhs: Range) -> Pr // MARK: - NSPredicate public func == (lhs: KeyPath, rhs: V) -> NSPredicate { - let attribute = Attribute((lhs as AnyKeyPath)._kvcKeyPathString!) - return attribute == rhs + return expression(for: lhs) == NSExpression(forConstantValue: rhs) } public func != (lhs: KeyPath, rhs: V) -> NSPredicate { - let attribute = Attribute((lhs as AnyKeyPath)._kvcKeyPathString!) - return attribute != rhs + return expression(for: lhs) != NSExpression(forConstantValue: rhs) } public func > (lhs: KeyPath, rhs: V) -> NSPredicate { - let attribute = Attribute((lhs as AnyKeyPath)._kvcKeyPathString!) - return attribute > rhs + return expression(for: lhs) > NSExpression(forConstantValue: rhs) } public func >= (lhs: KeyPath, rhs: V) -> NSPredicate { - let attribute = Attribute((lhs as AnyKeyPath)._kvcKeyPathString!) - return attribute >= rhs + return expression(for: lhs) >= NSExpression(forConstantValue: rhs) } public func < (lhs: KeyPath, rhs: V) -> NSPredicate { - let attribute = Attribute((lhs as AnyKeyPath)._kvcKeyPathString!) - return attribute < rhs + return expression(for: lhs) < NSExpression(forConstantValue: rhs) } public func <= (lhs: KeyPath, rhs: V) -> NSPredicate { - let attribute = Attribute((lhs as AnyKeyPath)._kvcKeyPathString!) - return attribute <= rhs + return expression(for: lhs) <= NSExpression(forConstantValue: rhs) } public func ~= (lhs: KeyPath, rhs: V) -> NSPredicate { - let attribute = Attribute((lhs as AnyKeyPath)._kvcKeyPathString!) - return attribute ~= rhs + return expression(for: lhs) ~= NSExpression(forConstantValue: rhs) } public func << (lhs: KeyPath, rhs: [V]) -> NSPredicate { - let attribute = Attribute((lhs as AnyKeyPath)._kvcKeyPathString!) - return attribute << rhs + return expression(for: lhs) << NSExpression(forConstantValue: rhs) } public func << (lhs: KeyPath, rhs: Range) -> NSPredicate { - let attribute = Attribute((lhs as AnyKeyPath)._kvcKeyPathString!) - return attribute << rhs + return expression(for: lhs) << NSExpression(forConstantValue: rhs) } diff --git a/Sources/QueryKit/QuerySet.swift b/Sources/QueryKit/QuerySet.swift index a1603bb..c63d7a8 100644 --- a/Sources/QueryKit/QuerySet.swift +++ b/Sources/QueryKit/QuerySet.swift @@ -223,8 +223,11 @@ extension QuerySet { :note: Returns nil if the operation could not be completed. */ public func exists() throws -> Bool { - let result:Int = try count() - return result > 0 + let fetchRequest = self.fetchRequest + fetchRequest.fetchLimit = 1 + + let result = try context.count(for: fetchRequest) + return result != 0 } // MARK: Deletion