# CSListMonitor

    @available(OSX 10.12, *)
    @objc
    public final class CSListMonitor : NSObject

The `CSListMonitor` serves as the Objective-C bridging type for `ListMonitor<T>`.

See also

`ListMonitor`

### Public (Accessors)

- `subscript(_:)`

  Returns the object at the given index within the first section. This subscript indexer is typically used for `CSListMonitor`s created without section groupings.

  #### Declaration

  Swift

      @objc
      public subscript(index: Int) -> Any { get }

  #### Parameters

  `index` | the index of the object. Using an index above the valid range will raise an exception.

  #### Return Value

  the `NSManagedObject` at the specified index

- `objectAtSafeIndex(_:)`

  Returns the object at the given index, or `nil` if out of bounds. This indexer is typically used for `CSListMonitor`s created without section groupings.

  #### Declaration

  Swift

      @objc
      public func objectAtSafeIndex(_ index: Int) -> Any?

  #### Parameters

  `index` | the index for the object. Using an index above the valid range will return `nil`.

  #### Return Value

  the `NSManagedObject` at the specified index, or `nil` if out of bounds

- `objectAtSectionIndex(_:itemIndex:)`

  Returns the object at the given `sectionIndex` and `itemIndex`. This indexer is typically used for `CSListMonitor`s created as sectioned lists.

  #### Declaration

  Swift

      @objc
      public func objectAtSectionIndex(_ sectionIndex: Int, itemIndex: Int) -> Any

  #### Parameters

  `sectionIndex` | the section index for the object. Using a `sectionIndex` with an invalid range will raise an exception.
  `itemIndex` | the index for the object within the section. Using an `itemIndex` with an invalid range will raise an exception.

  #### Return Value

  the `NSManagedObject` at the specified section and item index

- `objectAtSafeSectionIndex(_:safeItemIndex:)`

  Returns the object at the given section and item index, or `nil` if out of bounds. This indexer is typically used for `CSListMonitor`s created as sectioned lists.

  #### Declaration

  Swift

      @objc
      public func objectAtSafeSectionIndex(_ sectionIndex: Int, safeItemIndex itemIndex: Int) -> Any?

  #### Parameters

  `sectionIndex` | the section index for the object. Using a `sectionIndex` with an invalid range will return `nil`.
  `itemIndex` | the index for the object within the section. Using an `itemIndex` with an invalid range will return `nil`.

  #### Return Value

  the `NSManagedObject` at the specified section and item index, or `nil` if out of bounds

- `objectAtIndexPath(_:)`

  Returns the object at the given `NSIndexPath`. This subscript indexer is typically used for `CSListMonitor`s created as sectioned lists.

  #### Declaration

  Swift

      @objc
      public func objectAtIndexPath(_ indexPath: IndexPath) -> Any

  #### Parameters

  `indexPath` | the `NSIndexPath` for the object. Using an `indexPath` with an invalid range will raise an exception.

  #### Return Value

  the `NSManagedObject` at the specified index path

- `objectAtSafeIndexPath(_:)`

  Returns the object at the given `NSIndexPath`, or `nil` if out of bounds. This subscript indexer is typically used for `CSListMonitor`s created as sectioned lists.

  #### Declaration

  Swift

      @objc
      public func objectAtSafeIndexPath(_ indexPath: IndexPath) -> Any?

  #### Parameters

  `indexPath` | the `NSIndexPath` for the object. Using an `indexPath` with an invalid range will return `nil`.

  #### Return Value

  the `NSManagedObject` at the specified index path, or `nil` if out of bounds

- `hasObjects()`

  Checks if the `CSListMonitor` has at least one object in any section.

  #### Declaration

  Swift

      @objc
      public func hasObjects() -> Bool

  #### Return Value

  `YES` if at least one object in any section exists, `NO` otherwise

- `hasObjectsInSection(_:)`

  Checks if the `CSListMonitor` has at least one object the specified section.

  #### Declaration

  Swift

      @objc
      public func hasObjectsInSection(_ section: Int) -> Bool

  #### Parameters

  `section` | the section index. Using an index outside the valid range will return `NO`.

  #### Return Value

  `YES` if at least one object in the specified section exists, `NO` otherwise

- `objectsInAllSections()`

  Returns all objects in all sections

  #### Declaration

  Swift

      @objc
      public func objectsInAllSections() -> [NSManagedObject]

  #### Return Value

  all objects in all sections

- `objectsInSection(_:)`

  Returns all objects in the specified section

  #### Declaration

  Swift

      @objc
      public func objectsInSection(_ section: Int) -> [NSManagedObject]

  #### Parameters

  `section` | the section index. Using an index outside the valid range will raise an exception.

  #### Return Value

  all objects in the specified section

- `objectsInSafeSection(safeSectionIndex:)`

  Returns all objects in the specified section, or `nil` if out of bounds.

  #### Declaration

  Swift

      @objc
      public func objectsInSafeSection(safeSectionIndex section: Int) -> [NSManagedObject]?

  #### Parameters

  `section` | the section index. Using an index outside the valid range will return `nil`.

  #### Return Value

  all objects in the specified section, or `nil` if out of bounds

- `numberOfSections()`

  Returns the number of sections

  #### Declaration

  Swift

      @objc
      public func numberOfSections() -> Int

  #### Return Value

  the number of sections

- `numberOfObjects()`

  Returns the number of objects in all sections

  #### Declaration

  Swift

      @objc
      public func numberOfObjects() -> Int

  #### Return Value

  the number of objects in all sections

- `numberOfObjectsInSection(_:)`

  Returns the number of objects in the specified section

  #### Declaration

  Swift

      @objc
      public func numberOfObjectsInSection(_ section: Int) -> Int

  #### Parameters

  `section` | the section index. Using an index outside the valid range will raise an exception.

  #### Return Value

  the number of objects in the specified section

- `numberOfObjectsInSafeSection(safeSectionIndex:)`

  Returns the number of objects in the specified section, or `nil` if out of bounds.

  #### Declaration

  Swift

      @objc
      public func numberOfObjectsInSafeSection(safeSectionIndex section: Int) -> NSNumber?

  #### Parameters

  `section` | the section index. Using an index outside the valid range will return `nil`.

  #### Return Value

  the number of objects in the specified section, or `nil` if out of bounds

- `sectionInfoAtIndex(_:)`

  Returns the `NSFetchedResultsSectionInfo` for the specified section

  #### Declaration

  Swift

      @objc
      public func sectionInfoAtIndex(_ section: Int) -> NSFetchedResultsSectionInfo

  #### Parameters

  `section` | the section index. Using an index outside the valid range will raise an exception.

  #### Return Value

  the `NSFetchedResultsSectionInfo` for the specified section

- `sectionInfoAtSafeSectionIndex(safeSectionIndex:)`

  Returns the `NSFetchedResultsSectionInfo` for the specified section, or `nil` if out of bounds.

  #### Declaration

  Swift

      @objc
      public func sectionInfoAtSafeSectionIndex(safeSectionIndex section: Int) -> NSFetchedResultsSectionInfo?

  #### Parameters

  `section` | the section index. Using an index outside the valid range will return `nil`.

  #### Return Value

  the `NSFetchedResultsSectionInfo` for the specified section, or `nil` if the section index is out of bounds.

- `sections()`

  Returns the `NSFetchedResultsSectionInfo`s for all sections

  #### Declaration

  Swift

      @objc
      public func sections() -> [NSFetchedResultsSectionInfo]

  #### Return Value

  the `NSFetchedResultsSectionInfo`s for all sections

- `targetSectionForSectionIndexTitle(title:index:)`

  Returns the target section for a specified Section Index title and index.

  #### Declaration

  Swift

      @objc
      public func targetSectionForSectionIndexTitle(title: String, index: Int) -> Int

  #### Parameters

  `title` | the title of the Section Index
  `index` | the index of the Section Index

  #### Return Value

  the target section for the specified Section Index title and index.

- `sectionIndexTitles()`

  Returns the section index titles for all sections

  #### Declaration

  Swift

      @objc
      public func sectionIndexTitles() -> [String]

  #### Return Value

  the section index titles for all sections

- `indexOf(_:)`

  Returns the index of the `NSManagedObject` if it exists in the `CSListMonitor`‘s fetched objects, or `nil` if not found.

  #### Declaration

  Swift

      @objc
      public func indexOf(_ object: NSManagedObject) -> NSNumber?

  #### Parameters

  `object` | the `NSManagedObject` to search the index of

  #### Return Value

  the index of the `NSManagedObject` if it exists in the `CSListMonitor`‘s fetched objects, or `nil` if not found.

- `indexPathOf(_:)`

  Returns the `NSIndexPath` of the `NSManagedObject` if it exists in the `CSListMonitor`‘s fetched objects, or `nil` if not found.

  #### Declaration

  Swift

      @objc
      public func indexPathOf(_ object: NSManagedObject) -> IndexPath?

  #### Parameters

  `object` | the `NSManagedObject` to search the index of

  #### Return Value

  the `NSIndexPath` of the `NSManagedObject` if it exists in the `ListMonitor`‘s fetched objects, or `nil` if not found.

### Public (Observers)

- `addListObserver(_:)`

  Registers a `CSListObserver` to be notified when changes to the receiver’s list occur.

  To prevent retain-cycles, `CSListMonitor` only keeps `weak` references to its observers.

  For thread safety, this method needs to be called from the main thread. An assertion failure will occur (on debug builds only) if called from any thread other than the main thread.

  Calling `-addListObserver:` multiple times on the same observer is safe, as `CSListMonitor` unregisters previous notifications to the observer before re-registering them.

  #### Declaration

  Swift

      @objc
      public func addListObserver(_ observer: CSListObserver)

  #### Parameters

  `observer` | a `CSListObserver` to send change notifications to

- `addListObjectObserver(_:)`

  Registers a `CSListObjectObserver` to be notified when changes to the receiver’s list occur.

  To prevent retain-cycles, `CSListMonitor` only keeps `weak` references to its observers.

  For thread safety, this method needs to be called from the main thread. An assertion failure will occur (on debug builds only) if called from any thread other than the main thread.

  Calling `-addListObjectObserver:` multiple times on the same observer is safe, as `ListMonitor` unregisters previous notifications to the observer before re-registering them.

  #### Declaration

  Swift

      public func addListObjectObserver(_ observer: CSListObjectObserver)

  #### Parameters

  `observer` | a `CSListObjectObserver` to send change notifications to

- `addListSectionObserver(_:)`

  Registers a `CSListSectionObserver` to be notified when changes to the receiver’s list occur.

  To prevent retain-cycles, `CSListMonitor` only keeps `weak` references to its observers.

  For thread safety, this method needs to be called from the main thread. An assertion failure will occur (on debug builds only) if called from any thread other than the main thread.

  Calling `-addListSectionObserver:` multiple times on the same observer is safe, as `ListMonitor` unregisters previous notifications to the observer before re-registering them.

  #### Declaration

  Swift

      @objc
      public func addListSectionObserver(_ observer: CSListSectionObserver)

  #### Parameters

  `observer` | a `CSListSectionObserver` to send change notifications to

- `removeListObserver(_:)`

  Unregisters a `CSListObserver` from receiving notifications for changes to the receiver’s list.

  For thread safety, this method needs to be called from the main thread. An assertion failure will occur (on debug builds only) if called from any thread other than the main thread.

  #### Declaration

  Swift

      @objc
      public func removeListObserver(_ observer: CSListObserver)

  #### Parameters

  `observer` | a `CSListObserver` to unregister notifications to

### Public (Refetching)

- `isPendingRefetch`

  Returns `YES` if a call to `-refetch:` was made to the `CSListMonitor` and is currently waiting for the fetching to complete. Returns `NO` otherwise.

  #### Declaration

  Swift

      @objc
      public var isPendingRefetch: Bool { get }

- `refetch(_:)`

  Asks the `CSListMonitor` to refetch its objects using the specified series of `CSFetchClause`s. Note that this method does not execute the fetch immediately; the actual fetching will happen after the `NSFetchedResultsController`‘s last `controllerDidChangeContent(_:)` notification completes.

  `refetch(...)` broadcasts `listMonitorWillRefetch(...)` to its observers immediately, and then `listMonitorDidRefetch(...)` after the new fetch request completes.

  #### Declaration

  Swift

      @objc
      public func refetch(_ fetchClauses: [CSFetchClause])

  #### Parameters

  `fetchClauses` | a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. Note that only specified clauses will be changed; unspecified clauses will use previous values.