I am trying to fetch Request from my DB. but i am getting nil in the response. The fetch is ok because when i use this method i am getting "sometimes" Values. (i know that i have data in the DB ). i think that this is somehow related to threads issue or because i am using Multi-Context. So my Question is basically generic.
if i am saving some data in specific MOC let's call it MOC1 and then i want to fetch that data that i just save .. i can use any MOC ? ( assuming that i save the child and parent and i can see the change on the DB )
if i save data with MOC that use NSPrivateQueueConcurrencyType can i fetch with MOC NSMainQueueConcurrencyType? and the opposite way.. ?
i can fetch data on background thread or i have to fetch on the main Thread?
what is the connection between the Main thread and NSMainQueueConcurrencyType
what is the connection between the Background thread and NSPrivateQueueConcurrencyType Thanks,
UPDATE:
The thing is that i fetch some entity and change some flag to isSync = YES when i want to save it i use my save method:
-(void)saveDataToDBWithCompletionWithManagedObjectContext:(NSManagedObjectContext*)managedObjectContext withCompletion:(void (^)(BOOL succeeded ,NSError *error))completion {
if (managedObjectContext != nil) {
[managedObjectContext performBlockAndWait:^{
NSError *errorMsg = nil;
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&errorMsg]) {
// do some real error handling
NSLog(@"couldn't save Background Context, error %@, %@", errorMsg, [errorMsg userInfo]);
if (completion) {
completion(NO, errorMsg);
}
} else {
if (completion) {
completion(YES, nil);
}
}
}];
} else {
if (completion) {
completion(NO, nil);
}
}
}
This method get the NSManagedObjectContext, and save it in to the relevant NSManagedObjectContext. then i run my master save:
-(void)saveMasterDataToDBWithSync:(BOOL)toDoSync WithCompletion:(void (^)(BOOL succeeded ,NSError *error))completion {
NSError *errorMsg = nil;
if (self.masterManagedObjectContext != nil) {
if ([self.masterManagedObjectContext hasChanges] && ![self.masterManagedObjectContext save:&errorMsg]) {
if (completion) {
completion(NO, errorMsg);
}
} else {
if (toDoSync) {
// DO sync with Parse
}
if (completion) {
completion(YES, nil);
}
}
} else {
if (completion) {
completion(NO, nil);
}
}
}
When i check my DB the data is there! but when i will try to fetch it i can not see any thing.