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.