Note that there are some explanatory texts on larger screens.

plurals
  1. POCore Data with UIDocument: RelationShips of new Objects somwhow broken after didEnterBackground and reopen
    primarykey
    data
    text
    <p>I changed my app from a single context with sqlite store managed in the app delegate to UIManagedDocument (Like default Xcode template with Core Data activated). Now I have some strange behavior when trying to fetch objects that has been created since the current app startup, after I closed(backgrounded) and reopened the app.</p> <p>There are 2 Entities: Folder and Item. Folder to Item is a to-many-relationship.</p> <p>The predicate of my fetchedResultsController to display the items in the current folder looks like that:</p> <pre><code>[fetchRequest setEntity:[NSEntityDescription entityForName:@"Item" inManagedObjectContext:self.context]]; [fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"(folder == %@)", self.currentFolder]]; </code></pre> <p>This still works fine beside one situation: - I create a new folder, add some items to it - Then close (background) and reopen the app - Select this folder to be displayed in the TableView Then the fetch returns 0 results.</p> <p>As soon as I kill the app and reopen it, the items of the folder are displayed again (and the fetchRequests returns the correct number of items).</p> <p>I did some further testing inside the viewDidAppear with some manual fetchRequests without a fetchedResultsController. And I really don't understand how this can happen.</p> <p>Both fetchRequests are basically the same (and also identical to the fetchedResultController's one), but the first one doesn't have the predicate and then checks in a for loop whether the item's folder ist the viewController's currentFolder.</p> <p>From my understanding, this should result in the exact same behavior, but while the predicate fails after backgrounding, the fetching of all items + testing in the for loop works fine all time.</p> <pre><code>// Returns fetchResult.count = 0 for new created folders after backgrounding the app [fetchRequest1 setEntity:[NSEntityDescription entityForName:@"Item" inManagedObjectContext:self.context]]; [fetchRequest1 setPredicate:[NSPredicate predicateWithFormat:@"(folder == %@)", self.currentFolder]]; NSArray *fetchResult1 = [self.context executeFetchRequest:fetchRequest1 error:nil]; // This time get all items in the context withour predicate [fetchRequest2 setEntity:[NSEntityDescription entityForName:@"Item" inManagedObjectContext:self.context]]; [fetchRequest2 setPredicate:nil]; NSArray *fetchResult2 = [self.context executeFetchRequest:fetchRequest1 error:nil]; // Filter to get only the items in the current folder NSMutableArray *filteredFetchResults2 = [NSMutableArray mutableArrayWithCapacity:0]; for (Item *item in fetchResult2) { if (item.folder == self.currentFolder) [filteredFetchResults2 addObject:item]; } // filteredFetchResults2 holds the correct items even after backgrounding. Why?!? </code></pre> <p>How could that be?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload