Fix some compiler warnings, add more clean logs in merge notification handler

Add refresh helper
This commit is contained in:
Saul Mora
2013-02-03 11:13:23 -07:00
parent a9d25fba4e
commit a9a8d4fd3d
4 changed files with 25 additions and 8 deletions

View File

@@ -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];

View File

@@ -44,6 +44,7 @@
+ (NSArray *) MR_descendingSortDescriptors:(NSArray *)attributesToSortBy;
- (void) MR_obtainPermanentObjectID;
- (void) MR_refresh;
- (id) MR_inContext:(NSManagedObjectContext *)otherContext;
- (id) MR_inThreadContext;

View File

@@ -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;

View File

@@ -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) = ^{