|
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. |
SPONSORED Transform your career with the iOS Lead Essentials. Unlock over 40 hours of expert training, mentorship, and community support to secure your place among the best devs. Click for early access to this limited offer and a FREE crash course.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.