18
我在我的核心數據模型中定義了一個名爲「RemainingGaneProjections」的獲取請求。我想要執行該提取請求並按照實體的某個屬性對結果進行排序。我的代碼如下所示:將排序描述符應用於從模板創建的NSFetchRequest
NSFetchRequest *projectionsRequest = [model fetchRequestTemplateForName:@"RemainingGameProjections"];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"confidence" ascending:NO];
[projectionsRequest setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
當我嘗試執行該代碼時,出現以下消息崩潰:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Can't modify a named fetch request in an immutable model.'
我在這崩潰發生的調試確認,當我執行setSortDescriptors方法在我的NSFetchRequest上。我一直無法弄清楚爲什麼會發生這種情況。
對此處發生了什麼的任何解釋?當檢索需要排序的數據時,我應該使用另一種方法嗎?
我假設你還爲'projectionRequest'添加了一個相應的'release'。 –
不 - 我在爲這個項目使用ARC;) –