세 가지 다른 NSFetchedResultsController를 사용하여 sqlite 데이터베이스에서 데이터 레코드를 가져옵니다. 그 중 하나는 장치 (iOS 3.1.3)에서 테스트 할 때 힘든 시간을줍니다. 시뮬레이터 (iOS 4.2, deploymentTarget 3.1.3)에서 실행하면 정상적으로 작동합니다.알 수없는 객체를 반환하는 FetchedResultsController
장치에서 가져 오기는 요청한대로 NSDictionaries가 아닌 개체 또는 오류를 반환합니다. 여기
는 fetchedResultsController의 정의는 다음과 같습니다- (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;
}
입니다 실제 가져 오기 : 시뮬레이터에서
- (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.
그러나 기기에서 실행하면 다음과 같이 표시됩니다.
,2102011-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”.
왜 코어 데이터는 쿼리를 변경합니까?
정확하게 NSKnownKeysDictionary1은 무엇입니까? 왜 컨트롤러의 fetchedObjects에 액세스하려고하면 장치에 오류가 발생합니까?
아이디어가 있으십니까? 미리 감사드립니다!