Results Controller

  • A ResultsController manages data in a way that is usable by a collection view.

    • FetchedResultsController
    • RelationalResultsController
    See more

    Declaration

    Swift

    public protocol ResultsController : AnyObject
  • The ResultsControllerDelegate defines methods that allow you to respond to changes in the results controller.

    Use ResultChangeSet to easily track changes and apply them to a CollectionView

    See more

    Declaration

    Swift

    public protocol ResultsControllerDelegate : AnyObject
  • The types of changes reported to ResultsControllerDelegate

    • delete: The item was deleted
    • update: The item was updated
    • insert: The item was inserted
    • move: The item was moved

    Declaration

    Swift

    public enum ResultsControllerChangeType
  • Errors thrown by results controllers - unimplimented

    • unknown:

    Declaration

    Swift

    public enum ResultsControllerError : Error
  • 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.

    See more

    Declaration

    Swift

    public class MutableResultsController<Section, Element> : ResultsController where Section : SectionType, Element : ResultType
  • A FetchedResultsController provides the same data store and change reporting as a MutableResultsController but sources it’s contents from a CoreData context.

    Given an NSFetchRequest, the results from the provided context are fetched and analyzed to provide the data necessary to populate a CollectionView.

    The controller can also be sorted, grouped into sections and automatically updated when changes are made in the managed obejct context.

    See more

    Declaration

    Swift

    public class FetchedResultsController<Section, Element> : MutableResultsController<Section, Element> where Section : SectionType, Element : NSManagedObject
  • Extending on FetchedResultsController and it’s section grouping, this controller allows for sections to be created from a parent ententy.-

    In a FetchedResultsController (and NSFetchedResultsController) you would use sectionKeyPath to achieve the following:

    Things
       { sectionKeyPath : "Things" }
       { sectionKeyPath : "Things" }
    
    Not Things
       { sectionKeyPath : "Not Things" }
       { sectionKeyPath : "Not Things" }
    

    While this is great, it does not work well for the common Parent-Child data model. In a Department - Employee model for example we woul want:

    Sales {}
       Jim {}
       Samantha {}
    
    Managment {}
       Sarah {}
       Howard {}
    
    
    Delivery {}
       <No employees>
    

    In this case, both the parent and child are NSManagedObjects joined by a relationship. Also, notice the Delivery department has no employees. With a standard FetchedResultsController where sections consist of the available values in the fetched objects, the Delivery would not be included. With a RelationalResultsController though you can opt to fetch both the sections and object independently (see fetchSections).

    See more

    Declaration

    Swift

    public class RelationalResultsController<Section, Element> : FetchedResultsController<Section, Element> where Section : NSManagedObject, Element : NSManagedObject
  • A results controller that does not concern itself with the order of objects, but only their membership to the supplied fetch request.

    See more

    Declaration

    Swift

    public class FetchedSetController : ContextObserver