     }
     
     func fill(dictionary: NSDictionary) -> Self? {
-        let propertyNames: NSArray = self.propertyNames()
+        let propertyNames = self.propertyNames()
+        let propertyTypes = self.propertyTypes()
         
         for (key, value) in dictionary {
-            if (propertyNames.containsObject(key)) {
-                self.setValue(value, forKey: key as! String)
+            if propertyNames.containsObject(key),
+                let typeString = propertyTypes["\(key)"]! as? String {
+                    if typeString == NSStringFromClass(value.classForCoder) || typeString == "@"{
+                        self.setValue(value, forKey: key as! String)
+                    }
             }
         }
         

    
    private func propertyNamesForClass(aClass: AnyClass?) -> NSArray {
        var propertyCount: UInt32 = 0
        var propertyList = class_copyPropertyList(aClass, &propertyCount)
        var properties = NSMutableSet.new()
        var i: UInt32
        
        for (i = 0; i < propertyCount; i++) {
            let property: objc_property_t = propertyList[Int(i)]
            let propertyName = NSString(UTF8String: property_getName(property))
            

    
    private func propertyNames() -> NSArray {
        var reference: AnyClass = self.superclass!
        let properties = NSMutableSet.new()
        
        properties.addObjectsFromArray(propertyNamesForClass(self.classForCoder) as [AnyObject])
        
        while reference.superclass() != nil {
            properties.addObjectsFromArray(propertyNamesForClass(reference) as [AnyObject])
            reference = reference.superclass()!
        }
        
        return properties.allObjects
    }
    
    private func propertyTypesForClass(aClass: AnyClass?) -> Dictionary<String, String> {
        var propertyCount: UInt32 = 0
        let propertyList = class_copyPropertyList(aClass, &propertyCount)
        let propertyTypes = NSMutableDictionary.new()
        let cleanupSet = NSCharacterSet.init(charactersInString: "\"@(){}")

        for (var i: UInt32 = 0; i < propertyCount; i++) {
            let property: objc_property_t = propertyList[Int(i)]
            let propertyName = NSString(UTF8String: property_getName(property))
            let propertyAttributes = NSString(UTF8String: property_getAttributes(property))
