In my viewWillAppear I execute multiple fetch requests. I noticed that on the first fetch request, nothing is found even though I know items should be found. I tried sleeping the main thread before executing the first fetch request and sure enough items were found. I'm only running on the simulator too btw.
So my question is, does Core Data take some time to "initialize" or anything? Will I have to worry about this when testing on a device (I don't have developer membership yet so I can't test it on a device)? Is there any way to "check" if it is safe to execute a fetch request?
I also checked the NSError for the first fetch request with no delay and it was null.
EDIT:
My viewWillAppear code was requested so here it is. Not very helpful though.
[NSThread sleepForTimeInterval:0.1];
for (NSString *category in self.categories) {
[self updateSection:category];
}
self.cateogires is just my sections of my table view and updateSection: updates the sections.
EDIT2:
I did some further investigating with NSLog statements and here's what I found.
I added NSLog statements to log how many objects are found after a fetch request and also the current state of the document. For some reason I'm getting fetch results even though the document appears to be closed.
Category1 has 3 values
Doc is open? NO
Category2 has 6 values
Doc is open? NO
Category3 has 3 values
Doc is open? NO
Category4 has 2 values
Doc is open? NO
I think my problem is that I am not using the completionHandler of [myManagedDocument openWithCompletionHandler: ] to wait and execute my fetch request. However, why then, do I get fet results if I am querying when the document is closed?