iOS 5 Core Data freeze

前端 未结 7 912
清歌不尽
清歌不尽 2021-01-30 22:48

I try to do the following simple thing:

NSArray * entities = [context executeFetchRequest:inFetchRequest error:&fetchError];

Nothing fancy.

7条回答
  •  心在旅途
    2021-01-30 23:32

    Executing fetch request must happen from the thread where context was created.

    Remember it is not thread safe and trying to executeFetchRequest from another thread will cause unpredictable behavior.

    In order to do this correctly, use

    [context performBlock: ^{
         NSArray * entities = [context executeFetchRequest:inFetchRequest error:&fetchError];   
    }];
    

    This will executeFetchRequest in the same thread as context, which may or may not be the main thread.

提交回复
热议问题