Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warnings fix #131

Closed
wants to merge 11 commits into from
2 changes: 1 addition & 1 deletion Source/Categories/DataImport/NSObject+MagicalDataImport.m
Expand Up @@ -33,7 +33,7 @@ - (NSString *) MR_lookupKeyForAttribute:(NSAttributeDescription *)attributeInfo;

id value = [self valueForKeyPath:lookupKey];

for (int i = 1; i < kMagicalRecordImportMaximumAttributeFailoverDepth && value == nil; i++)
for (NSUInteger i = 1; i < kMagicalRecordImportMaximumAttributeFailoverDepth && value == nil; i++)
{
attributeName = [NSString stringWithFormat:@"%@.%d", kMagicalRecordImportAttributeKeyMapKey, i];
lookupKey = [[attributeInfo userInfo] valueForKey:attributeName];
Expand Down
12 changes: 6 additions & 6 deletions Source/Categories/NSManagedObject+MagicalDataImport.m
Expand Up @@ -202,7 +202,7 @@ - (void) MR_importValuesForKeysWithDictionary:(id)objectData
NSDictionary *relationships = [[self entity] relationshipsByName];
[self MR_setRelationships:relationships
forKeysWithDictionary:objectData
withBlock:^(NSRelationshipDescription *relationshipInfo, id objectData){
withBlock:^(NSRelationshipDescription *relationshipInfo, id blockObjectData){

NSManagedObject *relatedObject = nil;
if ([objectData isKindOfClass:[NSDictionary class]])
Expand All @@ -222,9 +222,9 @@ - (void) MR_importValuesForKeysWithDictionary:(id)objectData
}
else
{
relatedObject = [self MR_findObjectForRelationship:relationshipInfo withData:objectData];
relatedObject = [self MR_findObjectForRelationship:relationshipInfo withData:blockObjectData];
}
[relatedObject MR_importValuesForKeysWithDictionary:objectData];
[relatedObject MR_importValuesForKeysWithDictionary:blockObjectData];

[self MR_addObject:relatedObject forRelationship:relationshipInfo];
}];
Expand All @@ -250,13 +250,13 @@ - (void) MR_updateValuesForKeysWithDictionary:(id)objectData
NSDictionary *relationships = [[self entity] relationshipsByName];
[self MR_setRelationships:relationships
forKeysWithDictionary:objectData
withBlock:^(NSRelationshipDescription *relationshipInfo, id objectData) {
withBlock:^(NSRelationshipDescription *relationshipInfo, id blockObjectData) {

NSManagedObject *relatedObject = [self MR_findObjectForRelationship:relationshipInfo
withData:objectData];
withData:blockObjectData];
if (relatedObject == nil)
{
relatedObject = [[relationshipInfo destinationEntity] MR_createInstanceFromDictionary:objectData inContext:[self managedObjectContext]];
relatedObject = [[relationshipInfo destinationEntity] MR_createInstanceFromDictionary:blockObjectData inContext:[self managedObjectContext]];
}
else
{
Expand Down
29 changes: 24 additions & 5 deletions Source/Categories/NSManagedObjectContext+MagicalRecord.m
Expand Up @@ -17,6 +17,7 @@ @interface NSManagedObjectContext (MagicalRecordPrivate)

- (void) MR_mergeChangesFromNotification:(NSNotification *)notification;
- (void) MR_mergeChangesOnMainThread:(NSNotification *)notification;
- (void) runOnMainQueueWithoutDeadlocking:(void (^)(void))block;

@end

Expand Down Expand Up @@ -141,7 +142,10 @@ - (void) MR_mergeChangesOnMainThread:(NSNotification *)notification;
}
else
{
[self performSelectorOnMainThread:@selector(MR_mergeChangesFromNotification:) withObject:notification waitUntilDone:YES];
// [self performSelectorOnMainThread:@selector(MR_mergeChangesFromNotification:) withObject:notification waitUntilDone:YES];
[self runOnMainQueueWithoutDeadlocking:^{
[self MR_mergeChangesFromNotification:notification];
}];
}
}

Expand Down Expand Up @@ -219,7 +223,10 @@ - (BOOL) MR_saveOnMainThread;
{
@synchronized(self)
{
[self performSelectorOnMainThread:@selector(MR_saveWrapper) withObject:nil waitUntilDone:YES];
// [self performSelectorOnMainThread:@selector(MR_saveWrapper) withObject:nil waitUntilDone:YES];
[self runOnMainQueueWithoutDeadlocking:^{
[self MR_saveWrapper];
}];
}

return YES;
Expand Down Expand Up @@ -292,16 +299,16 @@ + (NSManagedObjectContext *) MR_contextWithStoreCoordinator:(NSPersistentStoreCo
MRLog(@"Creating context in Thread Isolation Mode");
context = [[NSManagedObjectContext alloc] init];
[context setPersistentStoreCoordinator:coordinator];
MR_AUTORELEASE(context);
)
PRIVATE_QUEUES_ENABLED(
MRLog(@"Creating context in Context Private Queue Mode");
context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
[context performBlockAndWait:^{
[context setPersistentStoreCoordinator:coordinator];
}];
MR_AUTORELEASE(context);
)

MR_AUTORELEASE(context);
}
return context;
}
Expand Down Expand Up @@ -332,7 +339,7 @@ + (NSManagedObjectContext *) MR_contextThatNotifiesDefaultContextOnMainThread;
PRIVATE_QUEUES_ENABLED
(
MRLog(@"Creating Context - Using Private queue mode");
context = [[self alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
context = [[[self alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType] autorelease];
if (context != [self MR_defaultContext])
{
[context setParentContext:[NSManagedObjectContext MR_defaultContext]];
Expand All @@ -342,4 +349,16 @@ + (NSManagedObjectContext *) MR_contextThatNotifiesDefaultContextOnMainThread;
return context;
}

#pragma mark -

- (void) runOnMainQueueWithoutDeadlocking:(void (^)(void))block {
if ([NSThread isMainThread]) {
MXLog(@"Running MR block from main thread");
block();
} else {
MXLog(@"Running MR block through dispatch_sync to main queue");
dispatch_sync(dispatch_get_main_queue(), block);
}
}

@end
2 changes: 1 addition & 1 deletion Source/Categories/NSPersistentStore+MagicalRecord.m
Expand Up @@ -66,7 +66,7 @@ + (NSURL *) MR_cloudURLForUbiqutiousContainer:(NSString *)bucketName;
{
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSURL *cloudURL = nil;
if ([fileManager respondsToSelector:@selector(URLForUbiquityContainerIdentifier:)])
if (([bucketName isKindOfClass:[NSString class]] && [bucketName length] > 0) && [fileManager respondsToSelector:@selector(URLForUbiquityContainerIdentifier:)])
{
cloudURL = [fileManager URLForUbiquityContainerIdentifier:bucketName];
}
Expand Down
5 changes: 4 additions & 1 deletion Source/CoreData+MagicalRecord.h
Expand Up @@ -29,7 +29,10 @@
#endif

#ifndef kCFCoreFoundationVersionNumber_iPhoneOS_5_0
#define kCFCoreFoundationVersionNumber_iPhoneOS_5_0 674.0
// Replacing this because encoutnering deadlocks. See https://github.com/magicalpanda/MagicalRecord/pull/114 for similar discussion
// TODO figure out how to get iOS5 supported properly
//#define kCFCoreFoundationVersionNumber_iPhoneOS_5_0 674.0
#define kCFCoreFoundationVersionNumber_iPhoneOS_5_0 9999.0
#endif

#ifndef kCFCoreFoundationVersionNumber_10_7
Expand Down
1 change: 1 addition & 0 deletions Source/MRCoreDataAction.m
Expand Up @@ -58,6 +58,7 @@ + (void) saveDataWithBlock:(void (^)(NSManagedObjectContext *localContext))block
localContext = [NSManagedObjectContext MR_contextThatNotifiesDefaultContextOnMainThread];
[localContext MR_observeiCloudChangesInCoordinator:defaultCoordinator];
#endif
NSLog(@"Created localContext: %@; mainContext=%@", localContext, mainContext);
[mainContext setMergePolicy:NSMergeByPropertyStoreTrumpMergePolicy];
[localContext setMergePolicy:NSOverwriteMergePolicy];
}
Expand Down