iOS 5 Core Data freeze

前端 未结 7 1115
清歌不尽
清歌不尽 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:33

    Thanks for the hints given in this page on how to solve this freezing issue which appeared on upgrading from iOS4. It has been the most annoying problem I have found since I started programming on iOS.

    I have found a quick solution for cases where there are just a few calls to the context from other threads.

    I just use performSelectorOnMainThread:

        [self performSelectorOnMainThread:@selector(stateChangeOnMainThread:) withObject: [NSDictionary dictionaryWithObjectsAndKeys:state, @"state", nil] waitUntilDone:YES];
    

    To detect the places where the context is called from another thread you can put a breakpoint on the NSLog on the functions where you call the context as in the following piece of code and just use performSelectorOnMainThread on them.

    if(![NSThread isMainThread]){
         NSLog(@"Not the main thread...");
    }
    

    I hope that this may be helpful...

提交回复
热议问题