CheckLists
A checklist allows you to post a subject to a channel. Channel participants can choose from the items you specify, and the results can be viewed by everyone in the channel.
Here is a sample of what a complete checklist implementation can look like:

Create Checklist
The following example creates a checklist for a potluck.
MMXChannel *channel;
NSArray *itemsNames = @[@"Buns", @"Burgers", @"Chips"];
NSMutableArray<MMXCheckListItem *>*items = [NSMutableArray new];
for (NSString *name in itemsNames) {
MMXCheckListItem *item = [[MMXCheckListItem alloc] init];
item.text = name;
[items addObject:item];
}
MMXCheckList *checklist = [MMXCheckList createCheckList:@"Items for potluck" subject:@"What items will you bring?" items:items extras:nil];
[checklist publishWithChannel:channel success:^(MMXMessage * message) {
//CheckList Created!
} failure:^(NSError * error) {
NSLog(@"error %@", error.localizedDescription);
}];
Listen for Incoming Checklist Identifiers
Participants of the channel can listen for incoming checklist identifiers, which contain a checklistId we can use to get the checklist object from the server.
[[MMXNotificationCenter defaultCenter] addWithContext:self forChannel:nil onReceive:^(MMXMessage * message) {
if ([message.contentType isEqualToString: [MMXObjectIdentifier contentType]] && ((MMXObjectIdentifier *)message.payload).objectType == [MMXCheckList mmxPayloadType]) {
NSString *checklistID = ((MMXObjectIdentifier *) message.payload).objectID;
}
}];
Get the checklist object from the server using a checklistId (checklist identifier).
NSString *checkListID;
[MMXCheckList checkListWithId:checkListID
success:^(MMXCheckList * checklist) {
// do something with checklist object
}
failure:^(NSError * error) {
NSLog(@"error %@", error.localizedDescription);
}];
The checklist object contains all the information needed to display a checklist in your user interface.
NSString *name = checklist.name; // A user-friendly name of the checklist.
NSString *subject = checklist.subject; // The subject of this checklist.
NSArray<MMXCheckListItem *>*items = checklist.items; // A list of the available checklist items
NSDictionary<NSString *, NSString*>*extras = checklist.extras; // A user-defined object used to store arbitrary data will can accessed from a {Max.CheckList} instance.
NSDate *endDate = checklist.endDate; // The date this checklist ends. After a checklist ends, users can no longer select items.
Checklist Items for Participants
Participants can choose one or more items.
MMXCheckListItem *item1 = checklist.deselectedItems[0];
MMXCheckListItem *item2 = checklist.deselectedItems[1];
NSArray *selectedItems = @[item1, item2];
[checklist selectItems:selectedItems
success:^(MMXMessage * message) {
//Items chosen.
} failure:^(NSError * error) {
NSLog(@"error %@", error.localizedDescription);
}];
Listen for Incoming CheckListSelections
Channel participants can listen for any incoming CheckListSelection that will be displayed in the user interface.
[[MMXNotificationCenter defaultCenter] addWithContext:self forChannel:nil onReceive:^(MMXMessage * message) {
if ([message.payload isKindOfClass: MMXCheckListSelection.class]) {
MMXCheckListSelection *checklistSelection = (MMXCheckListSelection *)message.payload;
NSString *checklistID = checklistSelection.checklistID;
NSString* checklistName = checklistSelection.name; // checklist name
NSString *checklistSubject = checklistSelection.subject; // checklist question
NSArray *checklistDeselections = checklistSelection.deselectedItems; // the deselectedItems property is a list of CheckListItems deseleted by the sender
NSArray *checklistSelections = checklistSelection.selectedItems; // the selectedItems property is a list of CheckListItems seleted by the sender
NSArray *checklistNewItems = checklistSelection.newItems; // the newItems property is a list of CheckListItems the sender has added to the checklist
NSString *senderUserId = message.sender.userID;
}
}];
If the current user has voted in the checklist, the selected CheckListOption(s) can be obtained from the checklist object.
MMXCheckList *myCheckList = ...
NSArray<MMXCheckListItem*>* myChoices = myCheckList.mySelections; // a list of CheckListItems selected by the current user
Obtain Checklist Results
There are several ways to obtain checklist results.
Get the latest checklist object from the server using a checklistId:
NSString *checkListID;
[MMXCheckList checkListWithId:checkListID
success:^(MMXCheckList * checklist) {
// do something with checklist object
}
failure:^(NSError * error) {
NSLog(@"error %@", error.localizedDescription);
}];
Refresh results for an existing checklist object:
MMXCheckList *checklist;
[checklist refreshResultsWithCompletion:^(MMXCheckList *checklist) {
//refreshed checklist
}];
Use a listener to update checklist object results from the incoming checklistSelection. This method saves a round-trip to the server, updating the checklist results dynamically when a checklistSelection is received.
MMXCheckListSelection *checklistSelection;
[checklist refreshResultsWithAnswer:checklistSelection];