Note that there are some explanatory texts on larger screens.

plurals
  1. POFetchedResultsController returning unknown object
    text
    copied!<p>I'm using three different NSFetchedResultsController to fetch data records from my sqlite database. One of them is giving me a hard time, when tested on a device (iOS 3.1.3). Running it in the simulator (iOS 4.2, deploymentTarget 3.1.3) works fine. </p> <p>On the device the fetch is returning objects, which are neither NSDictionaries, as requested, nor faults. </p> <p>Here is the definition of the fetchedResultsController:</p> <pre><code>- (NSFetchedResultsController *)fetchedResultsControllerForLocID { if (_fetchedResultsControllerForLocID != nil) return _fetchedResultsControllerForLocID; NSSortDescriptor *sortDescriptor_00 = [[NSSortDescriptor alloc] initWithKey: kLocationsDatabaseLocationIDKeyPath ascending: TRUE]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects: sortDescriptor_00, nil]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName: kLocationsDatabaseAlternateNameEntityName inManagedObjectContext: self.managedObjectContext]; [fetchRequest setEntity:entity]; [fetchRequest setFetchBatchSize: 80]; [fetchRequest setResultType: NSDictionaryResultType]; [fetchRequest setPropertiesToFetch: [NSArray arrayWithObject: kLocationsDatabaseLocationIDKeyPath]]; [fetchRequest setReturnsDistinctResults: TRUE]; [fetchRequest setReturnsObjectsAsFaults: FALSE]; [fetchRequest setSortDescriptors: sortDescriptors]; NSFetchedResultsController *theFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest: fetchRequest managedObjectContext: self.managedObjectContext sectionNameKeyPath: nil cacheName: kLocationDatabaseAltNameLocIDRequestCacheName]; self.fetchedResultsControllerForLocID = theFetchedResultsController; [fetchRequest release]; [theFetchedResultsController release]; [sortDescriptor_00 release]; [sortDescriptors release]; return _fetchedResultsControllerForLocID; } </code></pre> <p>Here is the actual fetch:</p> <pre><code>- (void) searchLocationsDBWithFRCFor: (NSString *) locationName { [NSFetchedResultsController deleteCacheWithName: kLocationDatabaseAltNameLocIDRequestCacheName]; NSString *normLocationName = [self normalizeString: locationName]; NSPredicate *searchPredicate = [NSPredicate predicateWithFormat:@"(%K &gt;= %@) &amp;&amp; (%K &lt;= %@)", kLocationsDatabaseLocationSearchNameKeyPath, normLocationName, kLocationsDatabaseLocationSearchNameKeyPath, [self upperBoundSearchString: normLocationName]]; [[self.fetchedResultsControllerForLocID fetchRequest] setPredicate: searchPredicate]; NSError *error = nil; if (![self.fetchedResultsControllerForLocID performFetch:&amp;error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } NSMutableArray *tempArray = [[NSMutableArray alloc] init]; //this line craches on the device: for(NSDictionary* tempIDDict in [self.fetchedResultsControllerForLocID fetchedObjects]) { [tempArray addObject: [tempIDDict objectForKey: kLocationsDatabaseLocationIDKeyPath]]; } searchPredicate = [NSPredicate predicateWithFormat:@"(%K IN %@)", kLocationsDatabaseLocationIDKeyPath, tempArray]; [tempArray release]; //some more fetching... } </code></pre> <p>In the simulator I get these SQL-Callbacks:</p> <pre><code>2011-01-22 20:31:33.660 App[24386:207] CoreData: sql: pragma cache_size=200 2011-01-22 20:31:33.661 App[24386:207] CoreData: sql: SELECT Z_VERSION, Z_UUID, Z_PLIST FROM Z_METADATA 2011-01-22 20:31:33.664 App[24386:207] CoreData: sql: SELECT DISTINCT t0.ZLOCATIONID FROM ZALTERNATENAME t0 WHERE ( t0.ZLOCATIONSEARCHNAME &gt;= ? AND t0.ZLOCATIONSEARCHNAME &lt;= ?) ORDER BY t0.ZLOCATIONID 2011-01-22 20:31:33.666 App[24386:207] CoreData: annotation: sql connection fetch time: 0.0015s 2011-01-22 20:31:33.666 App[24386:207] CoreData: annotation: total fetch execution time: 0.0024s for 6 rows. </code></pre> <p>However running it on the device, gives me this:</p> <pre><code>2011-01-22 20:39:07.318 App[241:207] CoreData: sql: pragma cache_size=1000 2011-01-22 20:39:07.324 App[241:207] CoreData: sql: SELECT Z_VERSION, Z_UUID, Z_PLIST FROM Z_METADATA 2011-01-22 20:39:07.348 App[241:207] CoreData: sql: SELECT 0, t0.Z_PK FROM ZALTERNATENAME t0 WHERE ( t0.ZLOCATIONSEARCHNAME &gt;= ? AND t0.ZLOCATIONSEARCHNAME &lt;= ?) ORDER BY t0.ZLOCATIONID 2011-01-22 20:39:07.386 App[241:207] CoreData: annotation: sql connection fetch time: 0.0374s 2011-01-22 20:39:07.388 App[241:207] CoreData: annotation: total fetch execution time: 0.0404s for 16 rows. 2011-01-22 20:39:07.400 App[241:207] CoreData: sql: SELECT DISTINCT t0.ZLOCATIONID FROM ZALTERNATENAME t0 WHERE t0.Z_PK IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ORDER BY t0.ZLOCATIONID LIMIT 80 2011-01-22 20:39:07.407 App[241:207] CoreData: annotation: sql connection fetch time: 0.0061s 2011-01-22 20:39:07.409 App[241:207] CoreData: annotation: total fetch execution time: 0.0085s for 6 rows. </code></pre> <p>Not too bad, if it wasn't followed by an error:</p> <pre><code>2011-01-22 20:39:07.411 App[241:207] *** -[NSKnownKeysDictionary1 objectID]: unrecognized selector sent to instance 0x1e4f80 2011-01-22 20:39:07.414 App[241:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSKnownKeysDictionary1 objectID]: unrecognized selector sent to instance 0x1e4f80' 2011-01-22 20:39:07.417 App[241:207] Stack: ( 861696817, 860329709, 861700631, 861203093, 861166272, 832412333, 832413791, 77245, 66451, 66643, 845720837, 861449139, 861447005, 861059891, 861060063, 834770799, 834765939, 12391, 12316 ) terminate called after throwing an instance of 'NSException' Program received signal: “SIGABRT”. </code></pre> <p>Why is Core Data altering the query, when running on the device?</p> <p>What exactly is a NSKnownKeysDictionary1? And why does trying to access the fetchedObjects of the controller gives me an error on the device?</p> <p>Any ideas? Thanks in advance!</p>
 

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