過去幾天我一直在煽動提取請求。每次我嘗試啓動視圖,它崩潰,出現此錯誤:核心數據提取請求出錯'NSFetchRequest找不到NSEntityDescription'
"Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSFetchRequest could not locate an NSEntityDescription for entity name 'VoiceNotes''"
我在另一個視圖中使用完全相同的代碼(除用不同的實體名稱),它完美的作品。實體名稱沒有問題,它與實體在數據模型中具有相同的名稱。
請問有人能幫助我嗎?
在此先感謝!
這是獲取方法的代碼:
- (void)setupFetchedResultsController
{
if (!self.managedObjectContext) {
id delegate = [[UIApplication sharedApplication] delegate];
self.managedObjectContext = [delegate managedObjectContext];
}
NSString *entityName = @"VoiceNotes";// Put your entity name here
NSLog(@"Setting up a Fetched Results Controller for the Entity named %@", entityName);
// Request
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityName];
NSLog(@"test after request");
//request.predicate = [NSPredicate predicateWithFormat:@"Role.name = Blah"];
// Sorting
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"toInfo.title"
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)]];
// Fetch
NSLog(@"test after request THE SECOND");
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
NSLog(@"test after request THE THIRD");
[self performFetch];
}
編輯: 我有我的數據模型,一個是無關的這個問題,兩三個實體具有之間運行的關係他們。這些被稱爲VoiceNotes和VoiceNotesInfo。
截圖核心數據模型:
您能否添加一些關於核心數據模型的細節?這聽起來像你沒有一個名爲'VoiceNotes'的實體。 – Simon
但問題是,我這樣做。我會在一秒鐘內添加一些細節。 – Oliver
這只是一個建議,所以它不能解決您的問題。如果從模型中自動生成NSManagedObject子類,那麼可以使用宏/函數的結果(我不記得)'NSStringFromClass'作爲實體名稱,傳遞類。這給你一個編譯器的類型檢查 – Francesco