Sending Data to Server via Socket.io

Viewed 44

I need to send a topic list to my server. When I do it via Postman and send this :

{
"topics" : ["UUID78912","UUID87681"]
}

Everything works perfectly in the system and I am able to pass this data to my server. But when I do it in Swift like this :

self.socket!.on(clientEvent: .connect) 
{data, ack in

        print("Socket Connected")
        if self.socket!.status == .connected {
        self.socket?.emit("topics", CustomData(topics: topicList), completion: 
      {
        print(CustomData(topics: topicList))
        print("Completed")
        })
  }

Where CustomData is :

struct CustomData : SocketData {
   let topics: Array<String>

   func socketRepresentation() -> SocketData {
       return ["topics" : topics]
   }
}

How do I pass the data in the exact format like I am doing in Postman?

0 Answers
Related