How can I get number of objects in section, NSFetchedResultsController Swift
You need to cast self.fetchedResultsController?.sections
to an Array
of NSFetchedResultsSectionInfo
objects:
if let s = self.fetchedResultsController?.sections as? [NSFetchedResultsSectionInfo]
Then you can pass the section
to the subscript and get the number of objects:
if let s = self.fetchedResultsController?.sections as? [NSFetchedResultsSectionInfo] {
d = s[section].numberOfObjects
}
I think the currently accepted answer by Mike S was pre Swift 2.0
The following is working for me (Swift 2.1):
if let sections = fetchedResultsController?.sections {
return sections[section].numberOfObjects
} else {
return 0
}