declare operators as static functions

This commit is contained in:
John Rommel Estropia
2017-02-19 20:05:23 +09:00
parent c40d17a6ad
commit 9ff1c9d545
2 changed files with 40 additions and 27 deletions
@@ -27,22 +27,6 @@ import Foundation
import CoreData
public func && (left: Where, right: Where) -> Where {
return Where(NSCompoundPredicate(type: .and, subpredicates: [left.predicate, right.predicate]))
}
public func || (left: Where, right: Where) -> Where {
return Where(NSCompoundPredicate(type: .or, subpredicates: [left.predicate, right.predicate]))
}
public prefix func ! (clause: Where) -> Where {
return Where(NSCompoundPredicate(type: .not, subpredicates: [clause.predicate]))
}
// MARK: - Where
/**
@@ -50,6 +34,30 @@ public prefix func ! (clause: Where) -> Where {
*/
public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
/**
Combines two `Where` predicates together using `AND` operator
*/
public static func && (left: Where, right: Where) -> Where {
return Where(NSCompoundPredicate(type: .and, subpredicates: [left.predicate, right.predicate]))
}
/**
Combines two `Where` predicates together using `OR` operator
*/
public static func || (left: Where, right: Where) -> Where {
return Where(NSCompoundPredicate(type: .or, subpredicates: [left.predicate, right.predicate]))
}
/**
Inverts the predicate of a `Where` clause using `NOT` operator
*/
public static prefix func ! (clause: Where) -> Where {
return Where(NSCompoundPredicate(type: .not, subpredicates: [clause.predicate]))
}
/**
The `NSPredicate` for the fetch or query
*/