Inherits from NSObject
Conforms to NSURLConnectionDataDelegate
NSURLConnectionDelegate
TKAutoCompleteDataSource
TKCalendarDataSource
TKCalendarDelegate
TKChartDataSource
TKChartDelegate
TKListViewDataSource
TKListViewDelegate
UICollectionViewDataSource
UICollectionViewDelegate
UITableViewDataSource
UITableViewDelegate
Declared in TKDataSource.h

Overview

TKDataSource is an adapter that consumes data from various sources and has functionality for data manipulations. It implements various data source protocols and can be used as a data source for TKChart, TKCalendar, TKListView, UITableView and UICollectionView.

Properties

allowItemsReorder

Determines whether items reordering is allowed or not.

@property (nonatomic) BOOL allowItemsReorder

Declared In

TKDataSource.h

currentItem

The current item. It is syncronized among all consumers of this class.

@property (nonatomic, weak, null_unspecified) id currentItem

Declared In

TKDataSource.h

displayKey

The display key used when extracting text from a single item.

@property (nonatomic, copy, nullable) NSString *displayKey

Declared In

TKDataSource.h

filterDescriptors

Returns a list with filter descriptors that is applied after the itemSource propety is set.

@property (nonatomic, strong, readonly, nonnull) NSArray<__kindofTKDataSourceFilterDescriptor*> *filterDescriptors

Declared In

TKDataSource.h

formatter

A formatted that is applied when extracting text from an item by using the displayKey property.

@property (nonatomic, strong, nullable) NSFormatter *formatter

Declared In

TKDataSource.h

groupDescriptors

Returns a list with group descriptors that will be applied when the itemSource propety is set.

@property (nonatomic, strong, readonly, nonnull) NSArray<__kindofTKDataSourceGroupDescriptor*> *groupDescriptors

Declared In

TKDataSource.h

groupItemSourceKey

The key used to extract items for specific group when grouping is applied. The key path is relative to the group object.

@property (nonatomic, copy, nullable) NSString *groupItemSourceKey

Declared In

TKDataSource.h

itemSource

The item source for this class. It can be a simple array with value types, complex objects or a dictionary.

@property (nonatomic, strong, nullable) id itemSource

Declared In

TKDataSource.h

items

An array view of the items contained in the itemSource after applying sorting, grouping and filtering operations.

@property (nonatomic, readonly, nonnull) NSArray *items

Declared In

TKDataSource.h

mapClass

When parsing data from JSON TKDataSource chaecks whether the mapClass property is set. If true it tries to create an instance of this class and initializes its properties with the JSON data.

@property (nonatomic, nullable) Class mapClass

Declared In

TKDataSource.h

mapCollectionsRecursively

When set to YES TKDataSource tries to map NSArray value proerties with instances of mapClass.

@property (nonatomic) BOOL mapCollectionsRecursively

Declared In

TKDataSource.h

propertyMap

Used when initializing an instance of mapClass to map its properties against JSON data. The format is: <class-property-name>:<json-field-name>

@property (nonatomic, strong, nullable) NSDictionary *propertyMap

Declared In

TKDataSource.h

settings

Provides the ability to customize the appearance of TKDataSource consumers. e.g. TKChart, TKCalendar, UITableView, etc.

@property (nonatomic, strong, readonly, nonnull) TKDataSourceSettings *settings

Declared In

TKDataSource.h

sortDescriptors

Returns a list with sort descriptors that is applied after the itemSource propety is set.

@property (nonatomic, strong, readonly, nonnull) NSArray<__kindofTKDataSourceSortDescriptor*> *sortDescriptors

Declared In

TKDataSource.h

valueKey

The value key used when extracting a value from a single item.

@property (nonatomic, copy, nullable) NSString *valueKey

Declared In

TKDataSource.h

Instance Methods

addFilterDescriptor:

Adds a new filter descriptor.

- (void)addFilterDescriptor:(TKDataSourceFilterDescriptor *__nonnull)filterDescriptor

Parameters

filterDescriptor

The filter descriptor to add.

Declared In

TKDataSource.h

addGroupDescriptor:

Adds a new group descriptor.

- (void)addGroupDescriptor:(TKDataSourceGroupDescriptor *__nonnull)groupDescriptor

Parameters

groupDescriptor

The group descriptor to be added.

Declared In

TKDataSource.h

addSortDescriptor:

Adds a new sort descriptor.

- (void)addSortDescriptor:(TKDataSourceSortDescriptor *__nonnull)sortDescriptor

Parameters

sortDescriptor

The sort descriptor to add.

Declared In

TKDataSource.h

enumerate:

Enumerates all items in the data source.

- (void)enumerate:(TKDataSourceEnumerator __nonnull)enumeratorBlock

Parameters

enumeratorBlock

The block function that is called when enumerating data source items.

Declared In

TKDataSource.h

filter:

Filters the items in the data source.

- (void)filter:(TKDataSourceFilterBlock __nonnull)filterBlock

Parameters

filterBlock

The block function that is used when filtering.

Declared In

TKDataSource.h

filterWithQuery:

Filters the items in the data source by using a query.

- (void)filterWithQuery:(NSString *__nonnull)filterQuery

Parameters

filterQuery

The filter query that is used to filter the items.

Declared In

TKDataSource.h

formatText:

Defines a textblock that is applied to get the text from an item when calling the textForItem method if specified.

- (void)formatText:(TKDataSourceFormatTextBlock __nonnull)formatTextBlock

Parameters

formatTextBlock

The block function that gets text from an item.

Declared In

TKDataSource.h

group:

Groups the items in the data source.

- (void)group:(TKDataSourceMapFunctionBlock __nonnull)keyForItem

Parameters

keyForItem

The group block function that is used to get a group key.

Declared In

TKDataSource.h

group:comparator:

Groups the items in the data source.

- (void)group:(TKDataSourceMapFunctionBlock __nonnull)keyForItem comparator:(NSComparator __nonnull)comparatorBlock

Parameters

keyForItem

The group block function that is used to get a group key.

comparatorBlock

The comparator to be used to sort groups.

Declared In

TKDataSource.h

groupWithKey:

Groups the items in the data source by using a property name.

- (void)groupWithKey:(NSString *__nonnull)propertyName

Parameters

propertyName

The property that is used to group the items.

Declared In

TKDataSource.h

groupWithKey:comparator:

Groups the items in the data source by using a property name.

- (void)groupWithKey:(NSString *__nonnull)propertyName comparator:(NSComparator __nonnull)comparatorBlock

Parameters

propertyName

The property that is used to group the items.

comparatorBlock

The comparator to be used to sort groups.

Declared In

TKDataSource.h

initWithArray:

Initializes the data source with an array of items.

- (instancetype __nonnull)initWithArray:(NSArray *__nonnull)items

Parameters

items

The array that is assigned to the itemSource property.

Declared In

TKDataSource.h

initWithArray:displayKey:

Initializes the data source with an array of items and parameters.

- (instancetype __nonnull)initWithArray:(NSArray *__nonnull)items displayKey:(NSString *__nullable)displayKey

Parameters

items

The array that is assigned to the itemSource property.

displayKey

The display key to use.

Declared In

TKDataSource.h

initWithArray:displayKey:valueKey:

Initializes the data source with an array of items and parameters.

- (instancetype __nonnull)initWithArray:(NSArray *__nonnull)items displayKey:(NSString *__nullable)displayKey valueKey:(NSString *__nullable)valueKey

Parameters

items

The array that is assigned to the itemSource property.

displayKey

The display key to use.

valueKey

The value key to use.

Declared In

TKDataSource.h

initWithDataFromJSONResource:ofType:rootItemKeyPath:

Initializes the data source with data coming from a JSON formatted resource.

- (instancetype __nonnull)initWithDataFromJSONResource:(NSString *__nonnull)name ofType:(NSString *__nonnull)type rootItemKeyPath:(NSString *__nullable)rootItemKeyPath

Parameters

name

The file name.

type

The file type.

rootItemKeyPath

The key path to the item containing the items collection that will be used in this data source.

Declared In

TKDataSource.h

initWithDataFromURL:dataFormat:rootItemKeyPath:completion:

Initializes the data source with data coming from a web service.

- (instancetype __nonnull)initWithDataFromURL:(NSString *__nonnull)url dataFormat:(TKDataSourceDataFormat)dataFormat rootItemKeyPath:(NSString *__nullable)rootItemKeyPath completion:(void ( ^ __nullable ) ( NSError *__nullable error ))completion

Parameters

url

The url where the data is located.

dataFormat

The format of the data coming from the web service.

rootItemKeyPath

The key path to the item containing the items collection that will be used in this data source.

completion

The block that is called after the data is loaded.

Declared In

TKDataSource.h

initWithItemSource:

Initializes the data source with a value for the itemSource property.

- (instancetype __nonnull)initWithItemSource:(id __nonnull)itemSource

Parameters

itemSource

The value for the itemSource property.

Declared In

TKDataSource.h

initWithJSONString:

Initializes the data source with a JSON formatted string.

- (instancetype __nonnull)initWithJSONString:(NSString *__nonnull)str

Parameters

str

The string containing JSON formatted data.

Declared In

TKDataSource.h

loadDataFromJSONResource:ofType:rootItemKeyPath:

Reads a JSON formatted resource and loads the parsed data in the data source.

- (void)loadDataFromJSONResource:(NSString *__nonnull)name ofType:(NSString *__nonnull)type rootItemKeyPath:(NSString *__nullable)rootItemKeyPath

Parameters

name

The file name.

type

The file type.

rootItemKeyPath

The key path to the item containing the items collection that is used in this data source.

Declared In

TKDataSource.h

loadDataFromJSONString:rootItemKeyPath:

Reads a JSON formatted string and loads the parsed data in the data source.

- (void)loadDataFromJSONString:(NSString *__nonnull)string rootItemKeyPath:(NSString *__nullable)rootItemKeyPath

Parameters

string

The string containing JSON formatted data.

rootItemKeyPath

The key path to the item containing the items collection that is used in this data source.

Declared In

TKDataSource.h

loadDataFromURL:dataFormat:rootItemKeyPath:completion:

Downloads data from a web service and initializes the data source with it.

- (void)loadDataFromURL:(NSString *__nonnull)url dataFormat:(TKDataSourceDataFormat)dataFormat rootItemKeyPath:(NSString *__nullable)rootItemKeyPath completion:(void ( ^ __nullable ) ( NSError *__nullable error ))completion

Parameters

url

The url where the data is located.

dataFormat

The format of the data coming from the web service.

rootItemKeyPath

The key path to the item containing the items collection that is used in this data source.

completion

A block that is called after the data is loaded.

Declared In

TKDataSource.h

map:

Apples the specified block to all items in the data source and allows changing their values.

- (void)map:(TKDataSourceMapFunctionBlock __nonnull)mapBlock

Parameters

mapBlock

The block function that is applied to all items.

Declared In

TKDataSource.h

moveItemAtIndex:toIndex:

Moves an item. This method is applicable only when grouping is not applied.

- (void)moveItemAtIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex

Parameters

fromIndex

The old item index.

toIndex

The new item index.

Declared In

TKDataSource.h

reduce:with:

Reduces the items collection to a single value and returns it.

- (id __nonnull)reduce:(id __nonnull)initialValue with:(TKDataSourceReduceFunctionBlock __nonnull)reduceBlock

Parameters

initialValue

The value to start with.

reduceBlock

The block function that is called when reducing the items collection.

Declared In

TKDataSource.h

reloadData

Reloads the data and applies again all descriptors. Call this method when the data has changed.

- (void)reloadData

Declared In

TKDataSource.h

removeAllFilterDescriptors

Removes all filter descriptors.

- (void)removeAllFilterDescriptors

Declared In

TKDataSource.h

removeAllGroupDescriptors

Removes all group descriptors.

- (void)removeAllGroupDescriptors

Declared In

TKDataSource.h

removeAllSortDescriptors

Removes all sort descriptors.

- (void)removeAllSortDescriptors

Declared In

TKDataSource.h

removeFilterDescriptor:

Removes a filter descriptor.

- (void)removeFilterDescriptor:(TKDataSourceFilterDescriptor *__nonnull)filterDescriptor

Parameters

filterDescriptor

The filter descriptor to remove.

Declared In

TKDataSource.h

removeGroupDescriptor:

Removes a group descriptor.

- (void)removeGroupDescriptor:(TKDataSourceGroupDescriptor *__nonnull)groupDescriptor

Parameters

groupDescriptor

The group descriptor to remove.

Declared In

TKDataSource.h

removeSortDescriptor:

Removes a sort descriptor.

- (void)removeSortDescriptor:(TKDataSourceSortDescriptor *__nonnull)sortDescriptor

Parameters

sortDescriptor

The sort descriptor to remove.

Declared In

TKDataSource.h

sort:

Sorts the items in the data source.

- (void)sort:(NSComparator __nonnull)comparatorBlock

Parameters

comparatorBlock

The comparator block function that is used when sorting.

Declared In

TKDataSource.h

sortWithKey:ascending:

Sorts the items in the data source by using a property name.

- (void)sortWithKey:(NSString *__nonnull)propertyName ascending:(BOOL)ascending

Parameters

propertyName

The property that is used to sort the items.

ascending

The sort direction.

Declared In

TKDataSource.h

textFromItem:inGroup:

Returns the text for the item. Uses the displayKey property.

- (NSString *__nullable)textFromItem:(id __nonnull)item inGroup:(TKDataSourceGroup *__nullable)group

Parameters

item

The item.

group

The group which owns this item. Can be nil if there is no grouping applied.

Declared In

TKDataSource.h

valueForItem:inGroup:

Returns the value of an item. Uses the valueKey property.

- (id __nullable)valueForItem:(id __nonnull)item inGroup:(TKDataSourceGroup *__nullable)group

Parameters

item

The item.

group

The group which owns this item. Can be nil if there is no grouping applied.

Declared In

TKDataSource.h