Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e947177
commit 5ed9a8e
Showing
34 changed files
with
1,108 additions
and
989 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// Aggregable.swift | ||
// CoreDataQueryInterface | ||
// | ||
// Created by Gregory Higley on 12/28/15. | ||
// Copyright © 2015 Prosumma LLC. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol Aggregable: Countable { | ||
typealias AggregateType: Attribute = Self | ||
func subquery(variable: String, predicate: AggregateType -> NSPredicate) -> NSExpression | ||
func subquery(predicate: AggregateType -> NSPredicate) -> NSExpression | ||
var average: AggregateType { get } | ||
var sum: AggregateType { get } | ||
var max: AggregateType { get } | ||
var min: AggregateType { get } | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// Countable.swift | ||
// CoreDataQueryInterface | ||
// | ||
// Created by Gregory Higley on 12/30/15. | ||
// Copyright © 2015 Prosumma LLC. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol Countable { | ||
var count: NSExpression { get } | ||
} | ||
|
||
extension NSExpression: Countable { | ||
public var count: NSExpression { | ||
return NSExpression(format: "%@.@count", self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// CustomExpressionConvertible.swift | ||
// CoreDataQueryInterface | ||
// | ||
// Created by Gregory Higley on 12/28/15. | ||
// Copyright © 2015 Prosumma LLC. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import CoreData | ||
|
||
public protocol CustomExpressionConvertible { | ||
var expression: NSExpression { get } | ||
} | ||
|
||
extension CustomExpressionConvertible { | ||
public func compare(rhs: Any?, type: NSPredicateOperatorType, options: NSComparisonPredicateOptions) -> NSPredicate { | ||
let rightExpression: NSExpression | ||
if let rhs = rhs as? CustomExpressionConvertible { | ||
rightExpression = rhs.expression | ||
} else { | ||
rightExpression = NSExpression(forConstantValue: rhs as! AnyObject?) | ||
} | ||
debugPrint(rightExpression) | ||
return NSComparisonPredicate(leftExpression: expression, rightExpression: rightExpression, modifier: .DirectPredicateModifier, type: type, options: options) | ||
} | ||
public func equalTo(rhs: Any?, options: NSComparisonPredicateOptions = []) -> NSPredicate { | ||
return compare(rhs, type: .EqualToPredicateOperatorType, options: options) | ||
} | ||
public func greaterThan(rhs: Any?, options: NSComparisonPredicateOptions = []) -> NSPredicate { | ||
return compare(rhs, type: .GreaterThanPredicateOperatorType, options: options) | ||
} | ||
public func greaterThanOrEqualTo(rhs: Any?, options: NSComparisonPredicateOptions = []) -> NSPredicate { | ||
return compare(rhs, type: .GreaterThanOrEqualToPredicateOperatorType, options: options) | ||
} | ||
public func lessThan(rhs: Any?, options: NSComparisonPredicateOptions = []) -> NSPredicate { | ||
return compare(rhs, type: .LessThanPredicateOperatorType, options: options) | ||
} | ||
public func lessThanOrEqualTo(rhs: Any?, options: NSComparisonPredicateOptions = []) -> NSPredicate { | ||
return compare(rhs, type: .LessThanOrEqualToPredicateOperatorType, options: options) | ||
} | ||
public func beginsWith(rhs: Any?, options: NSComparisonPredicateOptions = []) -> NSPredicate { | ||
return compare(rhs, type: .BeginsWithPredicateOperatorType, options: options) | ||
} | ||
public func contains(rhs: Any?, options: NSComparisonPredicateOptions = []) -> NSPredicate { | ||
return compare(rhs, type: .ContainsPredicateOperatorType, options: options) | ||
} | ||
public func endsWith(rhs: Any?, options: NSComparisonPredicateOptions = []) -> NSPredicate { | ||
return compare(rhs, type: .EndsWithPredicateOperatorType, options: options) | ||
} | ||
public func among(rhs: [Any], options: NSComparisonPredicateOptions = []) -> NSPredicate { | ||
var expressions = [AnyObject]() | ||
for elem in rhs { | ||
let o = elem as! AnyObject | ||
let e = NSExpression(forConstantValue: o) | ||
expressions.append(e) | ||
} | ||
return compare(NSExpression(forAggregate: expressions), type: .InPredicateOperatorType, options: options) | ||
} | ||
public func like(rhs: Any?, options: NSComparisonPredicateOptions = []) -> NSPredicate { | ||
return compare(rhs, type: .LikePredicateOperatorType, options: options) | ||
} | ||
} | ||
|
||
extension NSExpression: CustomExpressionConvertible { | ||
public var expression: NSExpression { | ||
return self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// CustomPropertyConvertible.swift | ||
// CoreDataQueryInterface | ||
// | ||
// Created by Gregory Higley on 12/28/15. | ||
// Copyright © 2015 Prosumma LLC. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import CoreData | ||
|
||
public protocol CustomPropertyConvertible { | ||
var property: AnyObject { get } | ||
} | ||
|
||
extension String: CustomPropertyConvertible { | ||
public var property: AnyObject { | ||
return self | ||
} | ||
} | ||
|
||
extension NSPropertyDescription: CustomPropertyConvertible { | ||
public var property: AnyObject { | ||
return self | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.