|
I'm trying to write a dummy SMTP server for the desktop -- basically, a SwiftUI reimplementation of a JavaFX app I've been using for years. But first, I'm starting out really really simple. I've imported the BlueSocket library and started out with its example echo server. I have a UI that is just a checkbox (run/stop the server) and a text string that should display how many clients are currently connected. The server starts and stops just fine, but the UI isn't updating when a client connects. I think the problem is that I don't have the UI observing the state properly. Could someone please help me out with this? Here's the relevant code, I think:
|
|
im new to swiftUI but as far as i know in your server class you need to use @Published wrapper instead of @State. then observed object in your struct will see the obserevable object Server/ Smtp or whatever u have there |
|
|
|
i think in smtp class its better to create published var and delete objectwillchange that way will be easier to understand why that class is observable and whats gonna be observed by others. again im new to swiftui hopefully more experienced members will join this thread and give good tips. |
|
Okay, I've tried out a few things and I believe I've gotten to the right implementation. In case anyone is wondering, here's the short version:
ContentView winds up looking a little different:
|
|
good for you! and it looks much nicer now. i would recomment u watching cs193 course for swiftUI on youtube. i dont like the way that guy does the actual code (its for advanced users i guess) but the way he explains complex things like generics, property wrappers and organizing the code is pretty good. |
SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.