MutableResultsController

public class MutableResultsController<Section, Element> : ResultsController where Section : SectionType, Element : ResultType

A results controller not only manages data, it also provides an easy to use, consistent interface for working with CollectionViews. While a typical controller fetches and manages data changes internally, this slimmed down version leaves the manipulation of it’s content up to you so you can use the same interface with any type of data.

  • Returns true if a sectionKeyPath has been set

    Declaration

    Swift

    public var isSectioned: Bool { get }
  • A key path of the elements to use for section groupings

    Declaration

    Swift

    public func setSectionKeyPath(_ keyPath: KeyPath<Element, Section>?)
  • A key path of the elements to use for section groupings

    Declaration

    Swift

    public func setSectionKeyPath(_ keyPath: KeyPath<Element, Section?>)
  • The delegate to report changes to

    Declaration

    Swift

    public weak var delegate: ResultsControllerDelegate?
  • The number of sections in the controller

    Declaration

    Swift

    public var numberOfSections: Int { get }
  • The number of objects in a given section

    Declaration

    Swift

    public func numberOfObjects(in section: Int) -> Int

    Parameters

    section

    A section index

    Return Value

    The number of objects in the given section

  • A list of all objects in the controller

    For performance reasons it is preferred to use object(at:)

    Declaration

    Swift

    public var allObjects: [Element] { get }
  • The list of sections in the controller

    For performance reasons accessing the controllers data should be done via the controller getters such as sectionInfo(forSectionAt:) or object(at:)

    Declaration

    Swift

    public var sections: [SectionInfo<Section, Element>] { get }
  • The value of sectionKeyPath for the objects in a given section

    If sectionKeyPath is set, each section is created to represent the value returned for that path by any of the objects contained within it. CustomDisplayStringConvertible is used to create a string from that value.

    If the objects have an attribute category of type int, and the sectionKeyPath is set to category, each category will represent the various Int values. Using CustomDisplayStringConvertible, that int will be returned as a string.

    For custom handling of this, use object(forSectionAt:)

    Declaration

    Swift

    public func sectionName(forSectionAt indexPath: IndexPath) -> String

    Parameters

    indexPath

    The index path of the section

    Return Value

    A string value (if any) for the given section

  • The object at a given index path

    Declaration

    Swift

    public func object(at indexPath: IndexPath) -> Element?

    Parameters

    indexPath

    An index path

    Return Value

    The object at the given indexPath (or nil if it is out of range)

  • Section info for a given index path

    Declaration

    Swift

    public func sectionInfo(at sectionIndexPath: IndexPath) -> SectionInfo<Section, Element>?

    Parameters

    sectionIndexPath

    A index path (item is not used)

    Return Value

    The section info if available

  • Section info for a given section

    Declaration

    Swift

    public func sectionInfo(at sectionIndex: Int) -> SectionInfo<Section, Element>?

    Parameters

    sectionIndex

    A section index

    Return Value

    The section info if available

  • The object represented by the given section (if sectionKeyPath is not nil)

    Declaration

    Swift

    public func object(forSectionAt sectionIndexPath: IndexPath) -> Section?

    Parameters

    sectionIndexPath

    An index path for the desired section

    Return Value

    The value for sectionKeyPath of each object in the section (or nil)

  • Section info representing a given section value (or nil)

    Declaration

    Swift

    public func sectionInfo(representing section: Section?) -> SectionInfo<Section, Element>?

    Parameters

    section

    A value that is represented by a section in the controller

    Return Value

    The section info if available

  • Check if an object exists in the controller

    Declaration

    Swift

    public func contains(object: Element) -> Bool

    Parameters

    object

    An object

    Return Value

    True if the object is currently in the controller’s data

  • Check if a section value exists in the controller

    Declaration

    Swift

    public func contains(sectionObject: Section) -> Bool

    Parameters

    sectionObject

    A section value

    Return Value

    True if a section representing the value exists in the controller’s data

  • The index path of a given object contained in the controller

    Declaration

    Swift

    public func indexPath(of object: Element) -> IndexPath?

    Parameters

    object

    An object contained in the controller

    Return Value

    The index path for the given object

  • The index path of the section represented by section info

    Declaration

    Swift

    public func indexPath(of sectionInfo: SectionInfo<Section, Element>) -> IndexPath?

    Parameters

    sectionInfo

    Info for the section

    Return Value

    The index path of the section matching the given info (or nil)

  • The index path of the section that represents a value

    Section value refers the the value of sectionKeyPath for all objects in a section.

    Declaration

    Swift

    public func indexPathOfSection(representing sectionValue: Section?) -> IndexPath?

    Parameters

    sectionValue

    The value that the desired section represents

    Return Value

    The index path of the section (or nil)

  • Set pre-grouped content on the controller

    Declaration

    Swift

    public func setContent(_ content: [(Section, [Element])])

    Parameters

    content

    A list of section, [Element] tuples to set as the content

  • Set the content of the controller to be sorted and grouped according to options

    Declaration

    Swift

    public func setContent(sections: [Section] = [], objects: [Element])

    Parameters

    content

    An array of elements

  • Clears all data and stops monitoring for changes in the context.

    Declaration

    Swift

    public func reset()
  • Remove the section representing the given value

    Declaration

    Swift

    public func delete(section: Section)

    Parameters

    section

    A Section value represented by a section in the controller

  • Insert a section representing the provided value

    Declaration

    Swift

    public func insert(section: Section)

    Parameters

    section

    A Section value representing a section in the controller

  • Notify the controller that a section value has changed

    After an object is changed in a way that affects its representation as a section in the controller (i.e. sorting), the controller must be notified to process the change.

    Declaration

    Swift

    public func didUpdate(section: Section)

    Parameters

    section

    A section existing in the controller

  • Delete objects from the controller

    Declaration

    Swift

    public func delete<C>(objects deletedObjects: C) where Element == C.Element, C : Collection

    Parameters

    deletedObjects

    A collection objects in the controller

  • Delete an object from the controller

    Declaration

    Swift

    public func delete(object: Element)

    Parameters

    object

    An object in the controller

  • Insert multiple objects into the controller

    Declaration

    Swift

    public func insert<C>(objects newObjects: C) where Element == C.Element, C : Collection

    Parameters

    newObjects

    A collection of objects

  • Insert an object into the controller

    Declaration

    Swift

    public func insert(object: Element)

    Parameters

    object

    An object

  • Notify the controller that an existing object has been updated

    After an object is changed in a way that affects its section or sorting, the controller must be notified to process the change.

    Declaration

    Swift

    public func didUpdate(object: Element)

    Parameters

    object

    An existing object in the controller