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.

var myChannel: MMXChannel! var items = ["Buns", "Burgers", "Chips"].map({ (s) -> MMXCheckListItem in let item = MMXCheckListItem()! item.text = s return item }) // create a checklist var myCheckList = MMXCheckList.createCheckList("Items for potluck", subject: "What items will you bring?", items: items, extras: nil) myCheckList.publish(channel: myChannel, success: { (message) in //CheckList Created! }, failure: { error in //print("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. self, forChannel: nil, onReceive: { message in if let objectIdentifier = message.payload as? MMXObjectIdentifier, objectIdentifier.objectType == MMXCheckList.mmxPayloadType() { let checkListID = objectIdentifier.objectID } })

Get the checklist object from the server using a checklistId (checklist identifier).

let checkListID = ...; MMXCheckList.checkListWithId(checkListID, success: { checklist in // do something with checklist object }, failure: { error in //print("error \(error.localizedDescription)") })

The checklist object contains all the information needed to display a checklist in your user interface.

let name = // A user-friendly name of the checklist. let subject = myCheckList.subject // The subject of this checklist. let items = myCheckList.items // A list of the available checklist items. let extras = myCheckList.extras // A user-defined object used to store arbitrary data will can accessed from a {Max.CheckList} instance. let endDate = myCheckList.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.

// create an array of the CheckListItems chosen by the current user. let item1 = myCheckList.items[0] let item2 = myCheckList.items[1] let selecteditems = [item1, item2] myCheckList.selectItems(selecteditems, success: { (message) in //Items chosen. }, failure: { (error) in //print("error \(error.localizedDescription)") })

Listen for Incoming CheckListSelections

Channel participants can listen for incoming CheckListSelection to display them in the user interface. self, forChannel: nil, onReceive: { message in if let checklistSelection = message.payload as? MMXCheckListSelection, message.contentType == MMXCheckListSelection.contentType { let checkListID = checklistSelection.checklistID let checklistName = // checklist name let checklistSubject = checklistSelection.subject // checklist subject let checklistDeselections = checklistSelection.deselectedItems // the deselectedItems property is a list of CheckListItems deseleted by the sender let checklistSelections = checklistSelection.selectedItems // the selectedItems property is a list of CheckListItems seleted by the sender let checklistNewItems = checklistSelection.newItems // the newItems property is a list of CheckListItems the sender has added to the checklist let senderUserId = message.sender?.userID } })

If the current user has voted in the checklist, the selected CheckListOption(s) can be obtained from the checklist object.

let myCheckList = ... let 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:

    var checkListID = ... MMXCheckList.checkListWithId(checkListID, success: { checklist in // do something with checklist object }, failure: { error in //print("error \(error.localizedDescription)") })

  • Refresh results for an existing checklist object:

    var myCheckList = ...; myCheckList.refreshResults(completion: { checklist in //refreshed checklist })

  • Use a listener to update existing checklist objects from the incoming checklistSelection. This method saves a round-trip to the server, updating the checklist results dynamically when a checklistSelection is received.

    let checklistSelection = ... myCheckList.refreshResults(answer: checklistSelection)