如何在
Swift中的NSFetchedResultcController部分获取对象数?
if let s = self.fetchedResultsController?.sections as? NSFetchedResultsSectionInfo { }
给我的不能从'[AnyObject]’转发到非@objc协议类型NSFetchedResultsSectionInfo
var d = self.fetchedResultsController?.sections[section].numberOfObjects
给我没有名为’下标’的成员
解决方法
您需要将self.fetchedResultsController?.sections转换为NSFetchedResultsSectionInfo对象的数组:
if let s = self.fetchedResultsController?.sections as? [NSFetchedResultsSectionInfo]
然后你可以将该部分传递给下标并获得对象的数量:
if let s = self.fetchedResultsController?.sections as? [NSFetchedResultsSectionInfo] { d = s[section].numberOfObjects }