[英]How is the process called when getting persistent objects out of the persistent store?
[英]How to deal with faulted objects returned by fetchedResultsController when the returned object may also be deleted from the persistent store
dataObject
上的屬性時,我們會崩潰,因為由於數據已從持久存儲中刪除,因此無法完成故障。示例代碼:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = code_for_cell_reuse_here;
PersonModelObject *dataObject = (PersonModelObject *)[self.fetchedResultsController objectAtIndexPath:indexPath];
/* Point A */
cell.textLabel.text = dataObject.name;
cell.detailTextLabel.text = dataObject.parent.name;
return cell;
}
您需要注意來自其他線程的 NSManagedObjectContextDidSaveNotification 並刷新您的上下文。
這可以同步完成,通過使用 performSelectorOnMainThread 或使用塊阻塞主線程更新來避免競爭條件。
You can then either manually, or using refreshFromContextDidSaveNotification:mergeChanges: update your local managed object context, but if the volume of data is sufficiently large it might be easiest to just call -reset on the managed object context and -performFetch on the fetched results controller .
要回答您問題的另一個方面(希望更有用), NSFetchedResultsController
應該返回故障對象(即已加載的屬性),並且您可以使用NSFetchRequest.relationshipKeyPathsForPrefetching
來預先獲取故障關系。
-[NSManagedObject isDeleted]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.