         
         let attributeClassName = attributeDescription!.attributeValueClassName
         
-        // strings and numbers are standard json data types
-        if attributeClassName == "NSString" || attributeClassName == "NSNumber" {
-            
-            return attributeValue
-        }
-        
-        // date
-        if attributeClassName == "NSDate" {
-            
-            
+        switch attributeClassName {
+            
+            // strings and numbers are standard json data types
+            case "NSString", "NSNumber":
+                return attributeValue
+            
+            case "NSDate":
+                let date = attributeValue as NSDate
+                return date.ISO8601String()
+            
+            case "NSData":
+                let data = attributeValue as NSData
+                return data.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength)
         }
         
         // transformable value type
-        if attributeType == NSAttributeType.TransformableAttributeType {
+        if attributeDescription?.attributeType == NSAttributeType.TransformableAttributeType {
             
             // get transformer
             let valueTransformerName = attributeDescription?.valueTransformerName

            // custom transformer
            let transformer = NSValueTransformer(forName: valueTransformerName!)
            
            let data = transformer.transformedValue(convertedValue) as? NSData
            
            return (data != nil)
        }
        
        return false

    }
}

// MARK: - Extensions

private extension NSDate {
    
    class func ISO8601DateFormatter() -> NSDateFormatter {
        
        struct Static {
            static var onceToken : dispatch_once_t = 0
            static var instance : NSDateFormatter? = nil
        }
        dispatch_once(&Static.onceToken) {
            Static.instance = NSDateFormatter()
            Static.instance?.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZ"
        }
        return Static.instance!
    }
    
    class func dateWithISO8601String(ISO8601String: String) -> NSDate? {
        
        return self.ISO8601DateFormatter().dateFromString(ISO8601String)
    }
    
    func ISO8601String() -> String {
        
        return NSDate.ISO8601DateFormatter().stringFromDate(self)
    }
}

