kye kye - 1 year ago 98
Swift Question

Set tag or unique identifier for MSMessage

It is possible to set a unique

and or
for a
instance? My current app is based on data fetched from a server using an integer id as an identifier. When a previous message is selected I want to modify the view accordingly by fetching the
(if possible) of the current message and using that in a query to my server.

override func willBecomeActive(with conversation: MSConversation) {
//Retrive id from selected message
if conversation.selectedMessage != nil{
//Do things

Answer Source

You can use the the URL of the message to add in it an "id" key:

guard let components = NSURLComponents(string: myBaseURL) else {
    fatalError("Invalid base url")

let id = NSURLQueryItem(name: "id", value: yourIdHere)
components.queryItems = [id]

guard let url = components.url  else {
    fatalError("Invalid URL components.")

message.url = url

Use an hash of the date for your id or whatever you want

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download