From d04b4ca0850eee18fd399d4830b33e962d0f9111 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Mon, 24 Aug 2015 20:40:19 +0900 Subject: [PATCH] added utility for ListMonitor to return the index/indexPath of a specified object --- CoreStore/Observing/ListMonitor.swift | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CoreStore/Observing/ListMonitor.swift b/CoreStore/Observing/ListMonitor.swift index 36a8b97..f6f5318 100644 --- a/CoreStore/Observing/ListMonitor.swift +++ b/CoreStore/Observing/ListMonitor.swift @@ -273,6 +273,28 @@ public final class ListMonitor { return sections[section] } + /** + Returns the index of the `NSManagedObject` if it exists in the `ListMonitor`'s fetched objects, or `nil` if not found. + + - parameter object: the `NSManagedObject` to search the index of + - returns: the index of the `NSManagedObject` if it exists in the `ListMonitor`'s fetched objects, or `nil` if not found. + */ + public func indexOf(object: T) -> Int? { + + return (self.fetchedResultsController.fetchedObjects as? [T] ?? []).indexOf(object) + } + + /** + Returns the `NSIndexPath` of the `NSManagedObject` if it exists in the `ListMonitor`'s fetched objects, or `nil` if not found. + + - parameter object: the `NSManagedObject` to search the index of + - returns: the `NSIndexPath` of the `NSManagedObject` if it exists in the `ListMonitor`'s fetched objects, or `nil` if not found. + */ + public func indexPathOf(object: T) -> NSIndexPath? { + + return self.fetchedResultsController.indexPathForObject(object) + } + /** Registers a `ListObserver` to be notified when changes to the receiver's list occur.