Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-22-2011, 02:24 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 4
Xintare is on a distinguished road
Default FetchedResultsController returning unknown object

Hi there,

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.

On the device the fetch is returning objects, which are neither NSDictionaries, as requested, nor faults.

Here is the definition of the fetchedResultsController:

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;
    }
Here is the actual fetch:

Code:
    - (void) searchLocationsDBWithFRCFor: (NSString *) locationName
    {
        [NSFetchedResultsController deleteCacheWithName: kLocationDatabaseAltNameLocIDRequestCacheName];
        NSString *normLocationName = [self normalizeString: locationName];
        NSPredicate *searchPredicate = [NSPredicate predicateWithFormat:@"(%K >= %@) && (%K <= %@)", kLocationsDatabaseLocationSearchNameKeyPath, normLocationName, kLocationsDatabaseLocationSearchNameKeyPath, [self upperBoundSearchString: normLocationName]];
    
        [[self.fetchedResultsControllerForLocID fetchRequest] setPredicate: searchPredicate];
    
        NSError *error = nil;
    
        if (![self.fetchedResultsControllerForLocID performFetch:&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...
    }
In the simulator I get these SQL-Callbacks:

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 >= ? AND t0.ZLOCATIONSEARCHNAME <= ?) 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.
However running it on the device, gives me this:

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 >= ? AND t0.ZLOCATIONSEARCHNAME <= ?) 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.
Not too bad, if it wasn't followed by an error:

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”.
Why is Core Data altering the query, when running on the device?

What exactly is a NSKnownKeysDictionary1? And why does trying to access the fetchedObjects of the controller gives me an error on the device?

Any ideas? Thanks in advance!
Xintare is offline   Reply With Quote
Old 01-23-2011, 03:37 PM   #2 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 4
Xintare is on a distinguished road
Default

Maybe the crash log helps:

Code:
Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread:  0

Thread 0 Crashed:
0   libSystem.B.dylib             	0x0007e98c __kill + 8
1   libSystem.B.dylib             	0x0007e97c kill + 4
2   libSystem.B.dylib             	0x0007e96e raise + 10
3   libSystem.B.dylib             	0x0009361a abort + 34
4   libstdc++.6.dylib             	0x000453b0 __gnu_cxx::__verbose_terminate_handler() + 376
5   libobjc.A.dylib               	0x00005858 _objc_terminate + 104
6   libstdc++.6.dylib             	0x00043776 __cxxabiv1::__terminate(void (*)()) + 46
7   libstdc++.6.dylib             	0x000437ca std::terminate() + 10
8   libstdc++.6.dylib             	0x00043896 __cxa_throw + 74
9   libobjc.A.dylib               	0x00004714 objc_exception_throw + 64
10  CoreFoundation                	0x00094210 -[NSObject doesNotRecognizeSelector:] + 108
11  CoreFoundation                	0x0001aa8e ___forwarding___ + 490
12  CoreFoundation                	0x00011ab8 _CF_forwarding_prep_0 + 40
13  CoreData                      	0x00069aa6 _faultBatchAtIndex + 1386
14  CoreData                      	0x0006a058 -[_PFBatchFaultingArray countByEnumeratingWithState:objects:count:] + 100
15  App                        		0x000124e6 -[SearchGeoNamesForCityViewController searchLocationsDBWithFRCFor:] (SearchGeoNamesForCityViewController.m:151)
16  App                        		0x0000fa50 -[SearchGeoNamesViewController requestLocationFromLocationsDB:] (SearchGeoNamesViewController.m:568)
17  App                        		0x0000fb10 -[SearchGeoNamesViewController handleSearchForTerm:] (SearchGeoNamesViewController.m:578)
18  Foundation                    	0x0000ccfe __NSFireTimer + 130
19  CoreFoundation                	0x00056bac CFRunLoopRunSpecific + 2112
20  CoreFoundation                	0x00056356 CFRunLoopRunInMode + 42
21  GraphicsServices              	0x00003b2c GSEventRunModal + 108
22  GraphicsServices              	0x00003bd8 GSEventRun + 56
23  UIKit                         	0x00002768 -[UIApplication _run] + 384
24  UIKit                         	0x0000146c UIApplicationMain + 688
25  App                        		0x000024d0 main (main.m:14)
26  App                        		0x00002484 start + 32
What I understand is, that for some reason, on the device, Core Data is returning faults (crash log, line 13), although the fetchRequest is not supposed to. And when I try to enumerate the fetched objects he trying to use the objectID to get the object for the fault. But I'm not even sure, it's really a fault, since he is telling me, that the problem lies with the NSKnownKeysDictionary1 object and the unknown selector "objectID". Sounds like he is trying to treat the NSKnownKeyDictionary1 like a fault... ?!?! Or am I getting this completely wrong?
Xintare is offline   Reply With Quote
Reply

Bookmarks

Tags
core data, fetchedresultcontroller, iphone

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 360
10 members and 350 guests
7twenty7, dre, iAppDeveloper, jeroenkeij, Mah6447, Morrisone, sacha1996, Sami Gh, stanny, toon4413
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:42 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0