【问题标题】:Fast Enumeration of a NSFetchedResultNSFetchedResult 的快速枚举
【发布时间】:2014-11-15 21:41:51
【问题描述】:

所以我有一个NSFetchedResultsController。我可以正常显示数据。我有一种情况,我需要能够列举它们。所以我获取了如下所示的结果:

if (![[self fetchedResultsController] performFetch:&error]) {

        exit(-1);  // Fail
    }

在显示数据之前,我需要对数据进行一些处理,因此我将其分配给这样的数组:

 arrVacationResults = [fetchedResultsController fetchedObjects];

到目前为止完美运行。我现在有一个 fetchedObjects 数组。我尝试使用快速枚举,但如何引用每个数组中的内容。我以为这是一本字典,所以我尝试做类似的事情

for (NSDictionary *myVacation in arrVacationResults)
{

}

这失败了,因为在arrVacationResults 中它们不是NSDictionaries,那么它们是什么?

【问题讨论】:

  • 仅供参考 - 我希望您的代码中没有真正调用 exit。为什么不记录错误并优雅地处理问题?
  • 它在我的“待办事项清单”上。感谢@rmaddy 的提醒!

标签: ios nsfetchedresultscontroller fast-enumeration


【解决方案1】:

它是一个 NSManagedObjects 数组:

for (NSManagedObject *myVacation in arraVacationResults)
{
 //
 //  if you need to cast it as your entity
 //
    VacationResultEntity *entity = (VacationResultEntity *) myVacation;   
}

【讨论】:

    猜你喜欢
    • 2015-12-10
    • 1970-01-01
    • 2020-05-19
    • 2013-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多