SCSArticleQueryResultsController

@interface SCSArticleQueryResultsController : NSObject

This class is intended to efficiently manage the results of an article query to return an indexed list of articles to the caller.

You configure an instance of this controller with a specific query, and the fetches and pagination will automatically be handled for you. Any changes to the set of articles will be communicated through the use of the SCSArticleQueryResultsControllerDelegate, allowing UI state to be updated as needed.

  • The query to be performed. If a nil value is supplied, this indicates that no articles should be returned from this controller. Assigning new values to this property will result in the set of articles returned being changed, with the appropriate delegate calls made to update the caller’s state.

    Note

    When this property is changed, no network calls will be automatically made, only the locally-cached article information already stored will be returned immediately. If you wish for new information to be loaded that matches the supplied query, you must invoke loadNextPage: manually.

    Assigning a new query will result in the page loading to reset back to the first page of results.

    Any in-flight network actions being performed to load new articles will immediately be cancelled when a new query is assigned.

    Warning

    Whenever the query is assigned, the result set must reside within the same knowledgeManager instance, including categories and all other properties. The behavior is undefined when this condition is not met.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic, nullable) SCSArticleQuery *query;

    Swift

    @NSCopying var query: SCSArticleQuery? { get set }
  • The SCSKnowledgeManager instance this query controller will observe. All queries assigned to this controller must be scoped by the same knowledge manager.

    Declaration

    Objective-C

    @property (readonly, strong, nonatomic)
        SCSKnowledgeManager *_Nonnull knowledgeManager;

    Swift

    var knowledgeManager: SCSKnowledgeManager { get }
  • Indicates whether or not this controller is performing a network operation to load more content.

    Declaration

    Objective-C

    @property (readonly, getter=isLoadingMore, assign, nonatomic) BOOL loadingMore;

    Swift

    var isLoadingMore: Bool { get }
  • Indicates if there is any more content that can be loaded.

    Declaration

    Objective-C

    @property (readonly, assign, nonatomic) BOOL canLoadMore;

    Swift

    var canLoadMore: Bool { get }
  • When the device is offline and no previously-cached results for the exact search criteria is available, this property will cause the controller to attempt to approximate the search results based on the articles already cached in the database.

    Declaration

    Objective-C

    @property (getter=shouldApproximateResultsOffline, assign, readwrite, nonatomic)
        BOOL approxmiateResultsOffline;

    Swift

    var shouldApproximateResultsOffline: Bool { get set }
  • Delegate to receive updates about changes to the data set.

    Declaration

    Objective-C

    @property (readwrite, nonatomic, nullable)
        NSObject<SCSArticleQueryResultsControllerDelegate> *delegate;

    Swift

    weak var delegate: SCSArticleQueryResultsControllerDelegate? { get set }
  • Initializes a new query controller with the given query and knowledge manager. The query may be nil, see the query property for more information.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithQuery:(nullable SCSArticleQuery *)query
                         knowledgeManager:(nonnull SCSKnowledgeManager *)manager;

    Swift

    init(query: SCSArticleQuery?, knowledgeManager manager: SCSKnowledgeManager)

    Parameters

    query

    The query to perform, or nil if no query should be executed.

    manager

    The knowledge manager to scope the query searches within.

    Return Value

    Initialized instance.

  • The number of articles currently available from this controller.

    Declaration

    Objective-C

    - (NSUInteger)numberOfArticles;

    Swift

    func numberOfArticles() -> UInt
  • Returns the article at the given index, or nil if the index is out-of-bounds.

    Declaration

    Objective-C

    - (nullable SCSArticle *)articleAtIndex:(NSUInteger)index;

    Swift

    func article(at index: UInt) -> SCSArticle?
  • Returns the index within this controller where the supplied article can be found, or NSNotFound is returned if the article cannot be found within this query controller.

    Declaration

    Objective-C

    - (NSUInteger)indexForArticle:(nonnull SCSArticle *)article;

    Swift

    func index(for article: SCSArticle) -> UInt
  • Requests that a network operation be performed to load the next page, if available.

    Declaration

    Objective-C

    - (void)loadNextPage:(nullable void (^)(NSError *_Nullable __strong))completion;

    Swift

    func loadNextPage(_ completion: ((Error?) -> Void)? = nil)