I'm looking for something similar to event listener in Swift, I want the function to be executed because I have socket to send every time it finds out a variable is not nil, the checking of the variable must be very frequent because I want live data to be received on the server. How could I do it?
Asked
Active
Viewed 544 times
0
-
"as3" stands for ActionScript 3? – Ahmad F Oct 07 '17 at 16:25
-
Yes "AS3" is Adobe ActionScript 3 – Cro Oct 07 '17 at 16:25
-
you could check the *delegation* pattern, see [this](https://stackoverflow.com/questions/40501780/examples-of-delegates-in-swift-3/40503024#40503024). Note that the answer does include some of the patterns for letting objects talk to each other in iOS, in "Alternatives" section. – Ahmad F Oct 07 '17 at 16:27
-
You can also use closure pattern, as function are the first class citizen in swift, you can declare them as property and use them as event listener. – Aks Oct 07 '17 at 16:33
-
Do you mean didSet? – Script Kitty Oct 07 '17 at 17:52
-
Have you consulted the [Network Programming Topics](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/NetworkingTopics/Articles/UsingSocketsandSocketStreams.html)? – Code Different Oct 08 '17 at 02:35
-
Could someone give me a way to do this using delegation? – Cro Oct 08 '17 at 02:52