Using LDKContext
The context is a global data source for you to store any item for later usage.
/*!
* @discussion The single instance method for retrieving the context
used in swift classes
*/
+ (LDKContext * __nonnull)swiftContext;
/*!
* @discussion The single instance method for retrieving the context
used in all objective c classes
*/
+ (LDKContext * __nonnull)context;
/*!
* @discussion Retrieve item from context based on ContextEntry
* @param entryName The name of the entry defined in ContextEntry
* @return The associated LDMItem if found, nil otherwise
*/
- (LDMItem * __nullable)itemForEntryNamed:(NSString *__nonnull)entryName;
/*!
* @discussion Retrieve all items of a particular type in the context
* @param itemType the name of the item type
* @return An array of LDMItems found in the context
*/
- (NSArray *__nullable)itemsOfType:(NSString *__nonnull)itemType;
/*!
* @discussion Removes an item in the context based on ContextEntry
* @param entryName The name of the entry defined in ContextEntry
*/
- (void)removeItemForEntryNamed:(NSString *__nonnull)entryName;
/*!
* @discussion Add an item to the contexxt
* @param item The LDMItem to be added
*/
- (void)addItem:(LDMItem *__nonnull)item;
/*!
* @discussion Removes all items in the context
*/
- (void)reset;
The use of LDKContext was briefly touched on in the chapter Function Items. But using this class first requires configuration. In MC, look at the ContextEntry item blotter. Below is the JSON for one Context Entry, account.
"data": {
"entry": "Account",
"image": "",
"itemType": "Account",
"labelRow1": "\"Account\"",
"labelRow2": "name \"-\"accountId\"",
"disableRemove": false,
"hidden": true,
"touchAction": "",
"sortOrder": 15
}
You must be fill in entry and itemtype as they will uniquely define the item types allowed to be placed into the context. The other fields only have use in the LDKContextViewController (an easy way of viewing what is currently in your context).
So now with the ContextEntry item cretaed for Item, using the Liquid Core API, this can be done in code:
[[LDKContext context] addItem: someAccount];
This account can later be retrieved with:
NSArray results = [[LDKContext context] itemsOfType: @"Account"];
When referencing the context in the function item, you must first place an item in the context using the item below.