I am making my first IOS application and using JSON and core data for getting and storing my data.
But for some reason or another it won't open it's NSDocument
. This is what I am doing.
- (void)useDocument
{
if (![[NSFileManager defaultManager] fileExistsAtPath:[self.genkDatabase.fileURL path]]) {
// does not exist on disk, so create it
[self.genkDatabase saveToURL:self.genkDatabase.fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
NSLog(@"test1");
[self setupFetchedResultsController];
NSLog(@"test12");
[self fetchFlickrDataIntoDocument:self.genkDatabase];
}];
} else if (self.genkDatabase.documentState == UIDocumentStateClosed) {
NSLog(@"test2");
// exists on disk, but we need to open it
[self.genkDatabase openWithCompletionHandler:^(BOOL success) {
NSLog(@"test4");
[self setupFetchedResultsController];
NSLog(@"test5");
}];
} else if (self.genkDatabase.documentState == UIDocumentStateNormal) {
NSLog(@"test3");
// already open and ready to use
[self setupFetchedResultsController];
}
}
- (void)setupFetchedResultsController // attaches an NSFetchRequest to this UITableViewController
{
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"News"];
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"News.title" ascending:YES]];
// no predicate because we want ALL the Photographers
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:self.genkDatabase.managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
NSLog(@"test10");
}
When you look at my log, you see the following.
Test 2 Test 4 Test 10 Test 5
As you can see it opens it succefully. Then executes the method setupFetchedResultsController
. But then it suddenly stops. I don't get any errors.
What It normally should do is go to the fetchFlickrDataIntoDocument
method.
Can anybody help me please ?