문제

Each time I write a method using an NSFetchRequest I faithfully include some version of the following boilerplate code:

NSError * error = nil;
NSArray * result = [context executeFetchRequest: fetchRequest error: &error];
if (!result && error) {
    NSLog(@"Error fetching - %@", error.localizedDescription);
}

However, I can't remember having ever seen executeFetchRequest fail and have error populated.

Certainly executeFetchRequestcan fail (trying to create invalid SQL, say) but this raises an exception, rather than returning an error.

So, my question is this: is it worth checking error each time, or would I be better to save myself the time and just write:

NSArray * result = [context executeFetchRequest: fetchRequest error: NULL];
도움이 되었습니까?

해결책

It is always worth including it.

showing the error to an enduser is useless
BUT logging it is ALWAYS good as it may potentially help you to better locate & fix a bug

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top