Inherits from | NSObject |
Declared in | SGItemSet.h |
Overview
SGItemSet
is the abstract base class for item sets, providing the core request handling and pagination. Create instances of SGEventSet
, SGPerformerSet
, and SGVenueSet
to fetch paginated results.
Tasks
Modifying the API query
State change callbacks
-
onPageLoaded
A block assigned to
propertyonPageLoaded
will be called after each result page request has completed. -
onPageLoadFailed
A block assigned to
propertyonPageLoadFailed
will be called after a page request failed to load.
Fetching results
-
– fetchNextPage
Fetch the next page of results. If the set is already fetching
fetchNextPage
will do nothing. If all results have already been fetched (lastPageAlreadyFetched)fetchNextPage
will do nothing. -
– fetchPage:
Fetch a specific page of results. Usually you will want to call
fetchNextPage
instead, but in some cases you may want to refetch a specific page. -
– cancelFetch
Cancel an in progress results fetch.
-
– lastPageAlreadyFetched
Returns YES if the last page of results has already been fetched.
-
– fetching
Returns YES if a results fetch is in progress.
Content inspection
-
– lastFetchedPage
Returns the page number of the last fetched page.
-
– totalPages
Returns the total number of pages available for the query. Note that if no pages have been fetched yet,
totalPages
will return 0. -
– array
Returns an
NSArray
of the items in the set. -
– orderdSet
Returns an
NSOrderedSet
of the items in the set. -
– firstObject
Returns the first item in the set.
-
– lastObject
Returns the last item in the set.
-
– count
Returns a count of the items in the set so far. Note that this is not the total available for the query, but instead the number of items fetched so far.
Resetting internal state
-
– reset
Reset the internal state of the set. Note that this doesn’t reset the query parameters. After being reset, a subsequent fetchNextPage will fetch the first page of results.
Status bar indicator
-
allowStatusBarSpinner
Whether to show a status bar activity indicator while fetching results. Default is YES.
property -
resultArrayKey
property -
– objectAtIndexedSubscript:
Properties
allowStatusBarSpinner 
@property (nonatomic, assign) BOOL allowStatusBarSpinner
Discussion
Whether to show a status bar activity indicator while fetching results. Default is YES.
Declared In
SGItemSet.h
onPageLoadFailed 
@property (nonatomic, copy) void ( ^ ) ( NSError *error ) onPageLoadFailed
Discussion
A block assigned to onPageLoadFailed
will be called after a page request failed to load.
events.onPageLoadFailed = ^(NSError *error) {
NSLog(@"error: %@", error);
};
Declared In
SGItemSet.h
onPageLoaded 
@property (nonatomic, copy) void ( ^ ) ( NSOrderedSet *newItems ) onPageLoaded
Discussion
A block assigned to onPageLoaded
will be called after each result page request has completed.
events.onPageLoaded = ^(NSOrderedSet *results) {
for (SGEvent *event in results) {
NSLog(@"event: %@", event.title);
}
};
Declared In
SGItemSet.h
query 
@property (nonatomic, strong) SGQuery *query
Discussion
An SGQuery instance for defining the parameters and filters of the API query.
SGEventSet *events = SGEventSet.eventsQuery;
events.query.search = @"new york mets";
events.query.perPage = 30;
Declared In
SGItemSet.h
Instance Methods
array 
- (NSArray *)array
Discussion
Returns an NSArray
of the items in the set.
Declared In
SGItemSet.h
cancelFetch 
- (void)cancelFetch
Discussion
Cancel an in progress results fetch.
Declared In
SGItemSet.h
count 
- (NSUInteger)count
Discussion
Returns a count of the items in the set so far. Note that this is not the total available for the query, but instead the number of items fetched so far.
Declared In
SGItemSet.h
fetchNextPage 
- (void)fetchNextPage
Discussion
Fetch the next page of results. If the set is already fetching fetchNextPage
will do nothing. If all results have already been fetched (lastPageAlreadyFetched) fetchNextPage
will do nothing.
Declared In
SGItemSet.h
fetchPage: 
- (void)fetchPage:(int)page
Discussion
Fetch a specific page of results. Usually you will want to call fetchNextPage
instead, but in some cases you may want to refetch a specific page.
Note that item sets contain only unique items, so a page refetch will only add any new results to the set, without duplicates. If the query hasn’t been modified then most likely no new items will be added.
Declared In
SGItemSet.h
fetching 
- (BOOL)fetching
Discussion
Returns YES if a results fetch is in progress.
Declared In
SGItemSet.h
lastFetchedPage 
- (int)lastFetchedPage
Discussion
Returns the page number of the last fetched page.
Declared In
SGItemSet.h
lastPageAlreadyFetched 
- (BOOL)lastPageAlreadyFetched
Discussion
Returns YES if the last page of results has already been fetched.
Declared In
SGItemSet.h
orderdSet 
- (NSOrderedSet *)orderdSet
Discussion
Returns an NSOrderedSet
of the items in the set.
Declared In
SGItemSet.h
reset 
- (void)reset
Discussion
Reset the internal state of the set. Note that this doesn’t reset the query parameters. After being reset, a subsequent fetchNextPage will fetch the first page of results.
Declared In
SGItemSet.h
totalPages 
- (int)totalPages
Discussion
Returns the total number of pages available for the query. Note that if no pages have been fetched yet, totalPages
will return 0.
Declared In
SGItemSet.h