diff --git a/GoldWars/GoldWars/MessageProtocol.swift b/GoldWars/GoldWars/MessageProtocol.swift index 3d6d14f..21ed95c 100644 --- a/GoldWars/GoldWars/MessageProtocol.swift +++ b/GoldWars/GoldWars/MessageProtocol.swift @@ -46,12 +46,10 @@ class MultiplayerNetwork{ } func sendPlayerMove(unitcount:Int) { - var playerMoveMsg = PlayerMove(messageType: MessageType.PlayerMove, unitCount: unitcount) - - - let data = Data(bytes: &playerMoveMsg, count: MemoryLayout.size) - - sendData(data: data) + let playerMoveMsg = PlayerMove(messageType: MessageType.PlayerMove, unitCount: unitcount) + let encoder = JSONEncoder() + let encoded = (try? encoder.encode(playerMoveMsg))! + sendData(data: encoded) } }