Learning Mobile Development
Simple iOS Chat App in 50 Lines of Code
To complete my collection of Simple Chat across iOS, Android, and Web through WebSocket
Published in
2 min readNov 6, 2021
I have previously done the Web chat with Node.js, and also the Android Simple Chat App. To feel complete, I also created a simple iOS Web Chat here.
How it is done in iOS
1. Create an ObservableObject type class
First, let’s create an ObservableObject
type class, as we want to contain the messages that will get updated in the SwiftUI automatically when the messages are updated.
class WebSocketManager: ObservableObject {
@Published var messages: [String] = [] // other code}
2. Create the WebSocket object
Next, lets’ create the WebSocket Object. Unlike Android, we don’t need an external library for it. One can instantiate it directly.