 prefix public func !(left: Attribute<Bool>) -> NSComparisonPredicate {
     return left == false
 }
+
+
+// MARK: - private functions
+
+private func expressionForValue<T>(value: T) -> NSExpression {
+    let v: AnyObject = toAnyObject(value)
+    return NSExpression(forConstantValue: v)
+}
+
+private func toAnyObject<T>(value: T) -> AnyObject {
+    // TODO: Find a cleaner implementation
+    let mirror = reflect(value)
+    
+    if mirror.disposition == .Optional {
+        let dt = value.dynamicType
+        
+        // here we have to test the optional object type, one by one
+        if dt is NSObject?.Type {
+            let o = unsafeBitCast(value, Optional<NSObject>.self)
+            if let v = o.0 {
+                return v
+            }
+        }
+        else if dt is NSString?.Type {
+            let o = unsafeBitCast(value, Optional<NSString>.self)
+            if let v = o.0 {
+                return v
+            }
+        }
+        else if dt is NSDate?.Type {
+            let o = unsafeBitCast(value, Optional<NSDate>.self)
+            if let v = o.0 {
+                return v
+            }
+        }
+        else if dt is NSDecimalNumber?.Type {
+            let o = unsafeBitCast(value, Optional<NSDecimalNumber>.self)
+            if let v = o.0 {
+                return v
+            }
+        }
+        else if dt is NSNumber?.Type {
+            let o = unsafeBitCast(value, Optional<NSNumber>.self)
+            if let v = o.0 {
+                return v
+            }
+        }
+        else if dt is NSData?.Type {
+            let o = unsafeBitCast(value, Optional<NSData>.self)
+            if let v = o.0 {
+                return v
+            }
+        }
+        
+        //
+        if dt is String?.Type {
+            let o = unsafeBitCast(value, Optional<String>.self)
+            if let v = o.0 {
+                return v as NSString
+            }
+        }
+        else if dt is Int?.Type {
+            let o = unsafeBitCast(value, Optional<Int>.self)
+            if let v = o.0 {
+                return NSNumber(integer: v)
+            }
+        }
+        else if dt is Int64?.Type {
+            let o = unsafeBitCast(value, Optional<Int64>.self)
+            if let v = o.0 {
+                return NSNumber(longLong: v)
+            }
+        }
+        else if dt is Int32?.Type {
+            let o = unsafeBitCast(value, Optional<Int32>.self)
+            if let v = o.0 {
+                return NSNumber(int: v)
+            }
+        }
+        else if dt is Int16?.Type {
+            let o = unsafeBitCast(value, Optional<Int16>.self)
+            if let v = o.0 {
+                return NSNumber(short: v)
+            }
+        }
+        else if dt is Double?.Type {
+            let o = unsafeBitCast(value, Optional<Double>.self)
+            if let v = o.0 {
+                return NSNumber(double: v)
+            }
+        }
+        else if dt is Float?.Type {
+            let o = unsafeBitCast(value, Optional<Float>.self)
+            if let v = o.0 {
+                return NSNumber(float: v)
+            }
+        }
+        else if dt is Bool?.Type {
+            let o = unsafeBitCast(value, Optional<Bool>.self)
+            if let v = o.0 {
+                return NSNumber(bool: v)
+            }
+        }
+    }
+    else {
+        //
+        if let v = value as? NSObject {
+            return v
+        }
+        
+        //
+        if let v = value as? String {
+            return v as NSString
+        }
+        else if let v = value as? Int {
+            return NSNumber(integer: v)
+        }
+        else if let v = value as? Int64 {
+            return NSNumber(longLong: v)
+        }
+        else if let v = value as? Int32 {
+            return NSNumber(int: v)
+        }
+        else if let v = value as? Int16 {
+            return NSNumber(short: v)
+        }
+        else if let v = value as? Double {
+            return NSNumber(double: v)
+        }
+        else if let v = value as? Float {
+            return NSNumber(float: v)
+        }
+        else if let v = value as? Bool {
+            return NSNumber(bool: v)
+        }
+    }
+    
+    return NSNull()
+}
+

public func ~=<T>(left: Attribute<T>, right: T) -> NSComparisonPredicate {
    return NSComparisonPredicate(
        leftExpression: left.expression,
        rightExpression: left.expressionForValue(right),
        modifier: .DirectPredicateModifier,
        type: .LikePredicateOperatorType,
        options: left.comparisonPredicateOptions()

public func >=<T>(left: Attribute<T>, right: T) -> NSComparisonPredicate {
    return NSComparisonPredicate(
        leftExpression: left.expression,
        rightExpression: expressionForValue(right),
        modifier: .DirectPredicateModifier,
        type: .GreaterThanOrEqualToPredicateOperatorType,
        options: left.comparisonPredicateOptions()
