Added predicateBuilder that create a NSPredicate from 3 parameters:
Attribute name
Attribute value (any object)
NSPredicateOperator
enum NSPredicateOperator : String {
case And = "AND"
case Or = "OR"
case In = "IN"
case Equal = "=="
case NotEqual = "!="
case GreaterThan = ">"
case GreaterThanOrEqual = ">="
case LessThan = "<"
case LessThanOrEqual = "<="
}
class func predicateBuilder(attribute: String!, value: AnyObject, predicateOperator: NSPredicateOperator ) -> NSPredicate? {
var predicate = NSPredicate(format: "%K \(predicateOperator.rawValue) $value", attribute)
predicate = predicate?.predicateWithSubstitutionVariables(["value" : value]);
return predicate
}
I have also added a new init method to allow the creation of more complex NSPredicate (the kind of firstCondition AND ( secondCondition OR thirdCondition)
Added predicateBuilder that create a NSPredicate from 3 parameters:
For example:
Using predicateBuilder I have improved findFirstOrCreateWithAttribute, now it works with all value and not only with strings
I have also added a new init method to allow the creation of more complex NSPredicate (the kind of firstCondition AND ( secondCondition OR thirdCondition)