diff --git a/MagicalRecord/Categories/DataImport/NSAttributeDescription+MagicalDataImport.m b/MagicalRecord/Categories/DataImport/NSAttributeDescription+MagicalDataImport.m index a5d05e2..bef36ca 100644 --- a/MagicalRecord/Categories/DataImport/NSAttributeDescription+MagicalDataImport.m +++ b/MagicalRecord/Categories/DataImport/NSAttributeDescription+MagicalDataImport.m @@ -42,7 +42,7 @@ do { NSMutableString *dateFormatKey = [kMagicalRecordImportCustomDateFormatKey mutableCopy]; if (index) { - [dateFormatKey appendFormat:@".%d", index]; + [dateFormatKey appendFormat:@".%lu", (unsigned long)index]; } index++; dateFormat = [[self userInfo] valueForKey:dateFormatKey]; diff --git a/MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalRecord.h b/MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalRecord.h index f64c204..55c9f04 100644 --- a/MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalRecord.h +++ b/MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalRecord.h @@ -44,6 +44,7 @@ + (NSArray *) MR_descendingSortDescriptors:(NSArray *)attributesToSortBy; - (void) MR_obtainPermanentObjectID; +- (void) MR_refresh; - (id) MR_inContext:(NSManagedObjectContext *)otherContext; - (id) MR_inThreadContext; diff --git a/MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalRecord.m b/MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalRecord.m index 628de40..12df5fb 100644 --- a/MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalRecord.m +++ b/MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalRecord.m @@ -226,6 +226,11 @@ static NSUInteger defaultBatchSize = kMagicalRecordDefaultBatchSize; return YES; } +- (void) MR_refresh; +{ + [[self managedObjectContext] refreshObject:self mergeChanges:YES]; +} + - (void) MR_obtainPermanentObjectID; { if ([[self objectID] isTemporaryID]) @@ -242,15 +247,23 @@ static NSUInteger defaultBatchSize = kMagicalRecordDefaultBatchSize; - (id) MR_inContext:(NSManagedObjectContext *)otherContext { - NSManagedObject *inContext = [otherContext objectRegisteredForID:[self objectID]]; //see if its already there - if (inContext == nil) + NSManagedObject *inContext = nil; + if ([[self objectID] isTemporaryID]) { - NSError *error = nil; - inContext = [otherContext existingObjectWithID:[self objectID] error:&error]; - + MRLog(@"Cannot load a temporary object across Managed Object Contexts"); + } + else + { + inContext = [otherContext objectRegisteredForID:[self objectID]]; //see if its already there if (inContext == nil) { - MRLog(@"Did not find object %@ in context %@: %@", self, [otherContext MR_description], error); + NSError *error = nil; + inContext = [otherContext existingObjectWithID:[self objectID] error:&error]; + + if (inContext == nil) + { + MRLog(@"Did not find object %@ in context '%@': %@", self, [otherContext MR_description], error); + } } } return inContext; diff --git a/MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalObserving.m b/MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalObserving.m index da49470..6e32e1d 100644 --- a/MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalObserving.m +++ b/MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalObserving.m @@ -71,8 +71,11 @@ NSString * const kMagicalRecordDidMergeChangesFromiCloudNotification = @"kMagica - (void) MR_mergeChangesFromNotification:(NSNotification *)notification; { + NSManagedObjectContext *fromContext = [notification object]; + if (fromContext == self) return; + MRLog(@"Merging changes from %@ to %@ %@", - [[notification object] MR_workingName], [self MR_workingName], + [fromContext MR_workingName], [self MR_workingName], ([NSThread isMainThread] ? @" *** on Main Thread ***" : @"")); void (^mergeBlock)(void) = ^{