added utility for ListMonitor to return the index/indexPath of a specified object

This commit is contained in:
John Estropia
2015-08-24 20:40:19 +09:00
parent 8ed6a78609
commit d04b4ca085

View File

@@ -273,6 +273,28 @@ public final class ListMonitor<T: NSManagedObject> {
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.