Just tried to use JSONSerialization:
func sendData(dictionaryWithData dictionary: Dictionary<String, Any>, toPeer targetPeers: [MCPeerID]) {
do {
let dataToSend = try JSONSerialization.data(withJSONObject: dictionary)
try session.send(dataToSend, toPeers: targetPeers, with: MCSessionSendDataMode.reliable)
}
catch {
}
}
Getting an error: 'Invalid type in JSON write (MCPeerID)'