mirror of
https://github.com/zhigang1992/MagicalRecord.git
synced 2026-01-12 17:32:18 +08:00
Fix some compiler warnings, add more clean logs in merge notification handler
Add refresh helper
This commit is contained in:
@@ -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];
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
+ (NSArray *) MR_descendingSortDescriptors:(NSArray *)attributesToSortBy;
|
||||
|
||||
- (void) MR_obtainPermanentObjectID;
|
||||
- (void) MR_refresh;
|
||||
- (id) MR_inContext:(NSManagedObjectContext *)otherContext;
|
||||
- (id) MR_inThreadContext;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) = ^{
|
||||
|
||||
Reference in New Issue
Block a user