                 if label == "metadata" {
                     continue
                 }
-                let value = anyValue as? CKRecordValue
-                record.setValue(value, forKey: label)
+                if let value = anyValue as? CKRecordValue {
+                    record.setValue(value, forKey: label)
+                } else {
+                    throw SerializationError.unsupportedSubType(label: label)
+                }
+//                let value = anyValue as? CKRecordValue
+//                record.setValue(value, forKey: label)
             }
         }
     }


    /* system fields */
    var metadata: Data? { get set }
    
    /* reads user fields */
    mutating func readUserFields(from record: CKRecord) // must be implemented by struct

    /* copies user fields via reflection */
    func writeUserFields(to record: CKRecord) throws
    
    /* read system and user fields form CKRecord */
    mutating func read(from record: CKRecord)
    
    /* generate CKRecord with user- and possibly system fields filled */
    func asCKRecord() throws -> CKRecord
    
    /* create empty CKRecord for zone and type */
    static func newCKRecord() -> CKRecord
    
    /* create empty CKRecord with name for type */
    static func create(name: String) -> CKRecord
    
}

//var AssociatedObjectHandle: UInt8 = 0

public extension RxCKRecord {
    
//    public var metadata: Data? {
//        get {
//            return objc_getAssociatedObject(self, &AssociatedObjectHandle) as? Data

        try self.writeUserFields(to: record)
        return record
    }

    public static func newCKRecord() -> CKRecord {
        let record = CKRecord(recordType: Self.type, zoneID: CKRecordZone(zoneName: Self.zone).zoneID)
        return record
