我有一個名爲Route
的實體,以及來自該實體的名爲Longitude
和Latitude
的兩個屬性。 該應用程序的功能很簡單:它將從Longitude
和Latitude
中獲取數據並創建一個NSArray。獲取核心數據中兩個屬性的正確方法
例如:
Route 1 has Longitude=2 and Latitude=41
Route 2 has Longitude=3 and Latitude=42
Route 3 has Longitude=4 and Latitude=43
所以結果將是一個NSArray的與內容:
{
[[CLLocation alloc] initWithLatitude:41 longitude:2],
[[CLLocation alloc] initWithLatitude:42 longitude:3],
[[CLLocation alloc] initWithLatitude:43 longitude:4],
}
但問題是,如果我取不同setupFetchedResultsController兩個屬性,我不能「連接「他們與他們合適的合作伙伴(我會得到2個分開的值列表)。是否有另一種方法來從2個屬性「連接」中獲取數據?
這是我的一個fetchedResultsController
如果有人需要看到:
- (NSFetchedResultsController *)fetchedLatitudController
{
if (_fetchedLatitudController != nil) {
return _fetchedLatitudController;
}
// 1 - Decide what Entity you want
NSString *entityName = @"Route"; // Put your entity name here
// 2 - Request that Entity
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityName];
// 4 - Sort it if you want
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"latitude"
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)]];
// 5 - Fetch it
self.fetchedLatitudController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
[self.fetchedLatitudController performFetch:nil];
return _fetchedLatitudController;
}
請顯示您的代碼。你如何獲取屬性? –
我使用setupfetchedResultsController的通用模板來提取。 – Rodrigo