Member-only story

Implement Polling in Swift

Must we poll?

Steven Curtis
3 min readMay 22, 2023
Photo by Markus Spiske on Unsplash

This article relies upon perform(_:with:afterDelay:) which (looking at that documentation) invokes a method on the current thread. This is rather nice, since we often want to be on the main thread to perform background tasks.

Wait though, why are we polling?

Reasons for polling

You might want to poll and check that your endpoint is responding. You may have an old backend which performs in such a way that you are required to poll it (and there is nothing that you can do about that).

However, polling is of course something which is rather up to the developer whether they will use it or not. There is nothing inherently wrong with polling, and perhaps this article will help out a user.

Of course, I’ve not used polling for the reasons detailed above.

So what have I used polling for in production?

In on context I used at a previous gig we had an API endpoint. The reason for this was to give the ability of the UI to display the App status (so it could be shown if the application would be under maintenance). Essentially the endpoint formed part of the availability strategy of the business, and provided a (at least reasonable) user experience. It is worth considering whether it is worth…

--

--

No responses yet