I had a crash while executing executeFetchRequest:error:
MyApp[595]
has active assertions beyond permitted time:
{(
<SBProcessAssertion: 0x1e5d1260> identifier: Suspending process: MyApp[595]
permittedBackgroundDuration: 10.000000 reason: suspend owner pid:29 preventSuspend
preventThrottleDownCPU preventThrottleDownUI
And this is my 开发者_开发知识库code:
NSString *predString = [NSString stringWithFormat:@"categoryId MATCHES '%@'", categoryId];
NSPredicate *predicate = [NSPredicate predicateWithFormat:predString];
[request setPredicate:predicate];
NSError *error = nil;
NSArray* objects = [context executeFetchRequest: request error: &error];
As far as I understand, the fetch, done synchronously in the main thread, took too much time, more than 10 secs, and the process was suspended.
Browsing in internet I found this nice solution to make the fetch async:
http://blog.zssz.me/2010/01/asynchronous-fetch-in-core-data.html
But i am wondering if actually my assumption is correct, and if there are simpler solutions to this problem. Thanks a lot.
You can't use the MATCHES
operator with an SQL store (which you are almost certainly using) because sqlite does not support regex. I would have expected it to error out instead of timing out but apparently not.
You want to use CONTAINS
or even better, ==
. If you have an attribute called catergoryID
it usually denotes an attribute with a specific unique value and not one that has a lot of minor variations. Using ==
/equals
will produce a vastly faster fetch.
The error is pretty clear :)
I'd try it in a background thread and see what happens.
精彩评论