diff --git a/Sources/ChainedClauseBuilder.swift b/Sources/ChainedClauseBuilder.swift index 1433d94..b5c714a 100644 --- a/Sources/ChainedClauseBuilder.swift +++ b/Sources/ChainedClauseBuilder.swift @@ -221,6 +221,11 @@ public extension From where D: NSManagedObject { public extension From where D: CoreStoreObject { + public func `where`(_ clause: (D) -> Where) -> FetchChainBuilder { + + return self.fetchChain(appending: clause(D.meta)) + } + public func select(_ keyPath: KeyPath.Required>) -> QueryChainBuilder { return self.select(R.self, [SelectTerm.attribute(keyPath)]) @@ -347,6 +352,14 @@ public extension FetchChainBuilder { } } +public extension FetchChainBuilder where D: CoreStoreObject { + + public func `where`(_ clause: (D) -> Where) -> FetchChainBuilder { + + return self.fetchChain(appending: clause(D.meta)) + } +} + public extension QueryChainBuilder { public func groupBy(_ clause: GroupBy) -> QueryChainBuilder { @@ -431,6 +444,11 @@ public extension QueryChainBuilder where D: NSManagedObject { public extension QueryChainBuilder where D: CoreStoreObject { + public func `where`(_ clause: (D) -> Where) -> QueryChainBuilder { + + return self.queryChain(appending: clause(D.meta)) + } + public func groupBy(_ keyPath: KeyPath.Required>) -> QueryChainBuilder { return self.groupBy(GroupBy(keyPath)) @@ -511,3 +529,12 @@ public extension SectionMonitorChainBuilder { ) } } + +@available(OSX 10.12, *) +public extension SectionMonitorChainBuilder where D: CoreStoreObject { + + public func `where`(_ clause: (D) -> Where) -> SectionMonitorChainBuilder { + + return self.sectionMonitorChain(appending: clause(D.meta)) + } +} diff --git a/Sources/WhereClauseType.swift b/Sources/WhereClauseType.swift index 38ece53..6c28131 100644 --- a/Sources/WhereClauseType.swift +++ b/Sources/WhereClauseType.swift @@ -21,42 +21,3 @@ public protocol WhereClauseType: AnyWhereClause { */ associatedtype ObjectType: DynamicObject } - -public extension WhereClauseType { - - /** - Combines two `Where` predicates together using `AND` operator. - - Warning: This operator overload is a workaround for Swift generics' inability to constrain by inheritance (https://bugs.swift.org/browse/SR-5213). In effect, this is less type-safe than other overloads because it allows AND'ing clauses of unrelated `DynamicObject` types. - */ - public static func && (left: Self, right: TWhere) -> Self { - - return Self.init(NSCompoundPredicate(type: .and, subpredicates: [left.predicate, right.predicate])) - } - - /** - Combines two `Where` predicates together using `AND` operator. - - Warning: This operator overload is a workaround for Swift generics' inability to constrain by inheritance (https://bugs.swift.org/browse/SR-5213). In effect, this is less type-safe than other overloads because it allows AND'ing clauses of unrelated `DynamicObject` types. - */ - public static func && (left: TWhere, right: Self) -> Self { - - return Self.init(NSCompoundPredicate(type: .and, subpredicates: [left.predicate, right.predicate])) - } - - /** - Combines two `Where` predicates together using `OR` operator. - - Warning: This operator overload is a workaround for Swift generics' inability to constrain by inheritance (https://bugs.swift.org/browse/SR-5213). In effect, this is less type-safe than other overloads because it allows OR'ing clauses of unrelated `DynamicObject` types. - */ - public static func || (left: Self, right: TWhere) -> Self { - - return Self.init(NSCompoundPredicate(type: .or, subpredicates: [left.predicate, right.predicate])) - } - - /** - Combines two `Where` predicates together using `OR` operator. - - Warning: This operator overload is a workaround for Swift generics' inability to constrain by inheritance (https://bugs.swift.org/browse/SR-5213). In effect, this is less type-safe than other overloads because it allows OR'ing clauses of unrelated `DynamicObject` types. - */ - public static func || (left: TWhere, right: Self) -> Self { - - return Self.init(NSCompoundPredicate(type: .or, subpredicates: [left.predicate, right.predicate])) - } -}