Created
August 23, 2013 10:23
-
-
Save robb/6317785 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MTLManagedObjectAdapter.m | |
- (NSPredicate *)uniquingPredicateForModel:(MTLModel<MTLManagedObjectSerializing> *)model { | |
NSSet *propertyKeys = nil; | |
if ([self.modelClass respondsToSelector:@selector(propertyKeysForManagedObjectUniquing)]) { | |
propertyKeys = [self.modelClass propertyKeysForManagedObjectUniquing]; | |
} | |
NSPredicate *predicate = nil; | |
for (NSString *propertyKey in propertyKeys) { | |
NSString *managedObjectKey = [self managedObjectKeyForKey:propertyKey]; | |
if (managedObjectKey) { | |
id transformedValue = [model valueForKeyPath:propertyKey]; | |
NSValueTransformer *attributeTransformer = [self entityAttributeTransformerForKey:propertyKey]; | |
if (attributeTransformer != nil) transformedValue = [attributeTransformer transformedValue:transformedValue]; | |
NSPredicate *subpredicate = [NSPredicate predicateWithFormat:@"%K == %@", managedObjectKey, transformedValue]; | |
predicate = [NSCompoundPredicate andPredicateWithSubpredicates:(predicate ? @[predicate, subpredicate] : @[subpredicate])]; | |
} | |
} | |
return predicate; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment