1

私は3つの異なるNSFetchedResultsControllerを使用して、sqliteデータベースからデータレコードを取得しています。そのうちの1人が、デバイス(iOS 3.1.3)でテストしたときに苦労しています。シミュレータ(iOS 4.2、deploymentTarget 3.1.3)で実行するとうまく動作します。未知のオブジェクトを返すFetchedResultsController

デバイス上でフェッチすると、NSDictionariesでもないオブジェクトも、要求どおりにフォルトが返されます。ここで

はfetchedResultsControllerの定義です:シミュレータで

- (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... 
} 

を、私はこれらのSQL-コールバックを得る:

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. 

しかしここで

- (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; 
} 

は、実際のフェッチでありますデバイス上で実行すると、私にはこれが与えられます:

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. 

ない、あまりにも悪い、それはエラーが続いていなかった場合:デバイス上で動作しているとき

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”. 

はなぜCore Dataは、クエリを変更していますか?

正確にNSKnownKeysDictionary1とは何ですか?そして、なぜコントローラのfetchedObjectsにアクセスしようとすると私のデバイスにエラーが出るのですか?

アイデア?前もって感謝します!

答えて

2

次の行を削除し、問題が解決するかどうか確認してください。 [fetchRequest setFetchBatchSize:80];

私のアプリが正常に動作したが、SDK 4.2で構築されたiOS 3.xデバイスでクラッシュしたのと同じ問題がありました。私はここで解決策を見つけた: setFetchLimit and sectionNameKeyPath on iPhone OS4 (XCode 3.2.3) cause crash

関連する問題