Skip to content

Instantly share code, notes, and snippets.

@mlcollard
Created May 4, 2018 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlcollard/2e413f7411330a7985d5d99c5208c84c to your computer and use it in GitHub Desktop.
Save mlcollard/2e413f7411330a7985d5d99c5208c84c to your computer and use it in GitHub Desktop.
func sendChat() {
// convert the string message into Data
guard let msg = self.messageField.text?.data(using: .utf8) else {
print("Error: ", #line)
return
}
// send the converted message
try? self.session.send(msg, toPeers: self.session.connectedPeers, with: .unreliable)
// update our own chat with the message we just sent
self.updateChat(name: "Local", text: self.messageField.text!)
// clear out the message field since the message has been sent
self.messageField.text = ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment