Core Data locks in background threads

后端 未结 2 1265
我在风中等你
我在风中等你 2021-01-30 22:19

I\'m getting locks in Core Data. I really don\'t understand the reason. Because I\'m creating a background MOC when I\'m processing in a background thread. Below you can see wha

2条回答
  •  醉梦人生
    2021-01-30 23:02

    Not totally sure if this applies to you but I was getting similar errors. I solved them by

    1. Using NSPrivateQueueConcurrencyType not NSConfinementConcurrencyType to take processing off the main thread.

    2. Putting executeFetchRequest inside MOC's performBlockAndWait.

    So in CoreDataHelper.m's fetchEntity method you would have something like this:

    [context performBlockAndWait:^{
       NSError *error = nil;
       NSArray *entities = [context executeFetchRequest:request error:&error];
    }];
    

提交回复
热议问题