|
Good afternoon Has anyone stumbled upon a good Network framework example to send/receive data over TCP? Just found this example which sends only: https://gist.github.com/ura14h/6f254f0f972f2cc430521acd6081e482 Like a simple:
thanks in advance richard |
|
Okay..found a solution which can receive the data.... Basically two classes called Connection() and Client().....but Connection() is used by Client() only.... Now the problem is that Connection() class gets the receiving data. So how do I get back the data into SwiftUI where I trigger the sending of a command like:
|
|
Hi, I'm new to the forum and am still figuring how the various post function works. Are you using the code block function to post your code or is that a screen shot because I see that it is color-coded? If it is a screenshot can you tell me how i can insert an image in my post? The insert image function provides a place-holder for me to insert a url but I'm not sure what to do with that. Thanks in advance |
|
|
|
Percival tells us some fun info:
and asks:
First rule of Forums!Use the search bar! At the top of each forum section is a search bar. Give it a try! Enter the text "post picture" or something similarly inquisitive! Voila! Results! Second rule of Forums.Don't hijack a forum question. This question is about network frameworks. You turned it into a question about posting graphics in a forum. Stop! Instead, create your own question. But before you do, see First rule of Forums! See-> How to post code |
|
From Apple Developer Tech Support person Quinn "The Eskimo": |
|
Well the snippet is exactly from there (o; The problem is how to get the received data back from the Connection() Class which is called by the Client() Class... I assume the Observable property can only be in the Client() Class, but it has no way of knowing when data was received (if any). Maybe rewrite those two classes into one is the only way? |
|
Eskimo uses his Client class to instantiate his Connection class. You can consider the Client class to be the view model. If you already have a view model class, you can let your view model instantiate the Client as an @Published var, or you can eliminate Client as a separate class by moving its methods and properties to your view model. In any of these 3 alternatives, only the view model needs to be an ObservableObject. Eskimo's method for handling received data is the closure that is the final parameter of self.nwConnection.receive() within Connection.setupReceive(). Eskimo merely prints the data. You need to store it in a property. If you make it a property of Connection, your view model will have a reference to it because that's where the Connection instance is stored. |
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.