From dd430ffee618ef5f0da2ffc3074ad8bf5715bead Mon Sep 17 00:00:00 2001 From: Taras Kalapun Date: Thu, 16 Jan 2014 17:17:06 +0100 Subject: [PATCH] Update NSManagedObject+MagicalDataImport.m If the primary attribute is `NSString` but we are receiving `NSNumber` the `NSPredicate` does not always convert it properly, so we will not get our existing object from a DB and the new duplicate will be created. This patch fixes such weird issue. --- .../NSManagedObject/NSManagedObject+MagicalDataImport.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalDataImport.m b/MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalDataImport.m index e81c7c271..f8ff2351d 100644 --- a/MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalDataImport.m +++ b/MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalDataImport.m @@ -286,6 +286,12 @@ + (id) MR_importFromObject:(id)objectData inContext:(NSManagedObjectContext *)co id value = [objectData MR_valueForAttribute:primaryAttribute]; + // Convert Number to String if the classes don't match + if ([[primaryAttribute attributeValueClassName] isKindOfClass:[NSString class]] && + [value isKindOfClass:[NSNumber class]]) { + value = [value description]; + } + NSManagedObject *managedObject = [self MR_findFirstByAttribute:[primaryAttribute name] withValue:value inContext:context]; if (managedObject == nil) {