From 2ed61fdb17f3ef3322a60abfdcf1cc457a0909c4 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Thu, 20 Aug 2015 12:15:20 +0900 Subject: [PATCH] added utilities to ListMonitor to extract all objects in specified sections --- CoreStore/Observing/ListMonitor.swift | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/CoreStore/Observing/ListMonitor.swift b/CoreStore/Observing/ListMonitor.swift index 0528fb1..f60dc20 100644 --- a/CoreStore/Observing/ListMonitor.swift +++ b/CoreStore/Observing/ListMonitor.swift @@ -150,18 +150,63 @@ public final class ListMonitor { return self[safeSectionIndex: indexPath.section, safeItemIndex: indexPath.item] } + /** + Returns all objects in all sections + + - returns: all objects in all sections + */ + public func objectsInAllSections() -> [T] { + + return (self.fetchedResultsController.fetchedObjects as? [T]) ?? [] + } + + /** + Returns all objects in the specified section + + - parameter section: the section index. Using an index outside the valid range will throw an exception. + - returns: all objects in the specified section + */ + public func objectsInSection(section: Int) -> [T] { + + return (self.fetchedResultsController.sections?[section].objects as? [T]) ?? [] + } + + /** + Returns all objects in the specified section + + - parameter section: the section index. Using an index outside the valid range will return `nil`. + - returns: all objects in the specified section + */ + public func objectsInSection(safeSectionIndex section: Int) -> [T]? { + + return (self.fetchedResultsController.sections?[section].objects as? [T]) ?? [] + } + /** Returns the number of sections + + - returns: the number of sections */ public func numberOfSections() -> Int { return self.fetchedResultsController.sections?.count ?? 0 } + /** + Returns the number of objects in all sections + + - returns: the number of objects in all sections + */ + public func numberOfObjects() -> Int { + + return self.fetchedResultsController.fetchedObjects?.count ?? 0 + } + /** Returns the number of objects in the specified section - parameter section: the section index + - returns: the number of objects in the specified section */ public func numberOfObjectsInSection(section: Int) -> Int { @@ -172,6 +217,7 @@ public final class ListMonitor { Returns the `NSFetchedResultsSectionInfo` for the specified section - parameter section: the section index + - returns: the `NSFetchedResultsSectionInfo` for the specified section */ public func sectionInfoAtIndex(section: Int) -> NSFetchedResultsSectionInfo {