Locking the view while loading API calls in Swift

A simple plan to stop multiple API calls when a user hammers a button

Steven Curtis
The Startup

--

This view doesn’t look locked, either.

It seems like an easy thing to lock the view in some situations (but you’d need to think carefully about your user journey and whether you really want to stop the user being able to interact with your App for some time). Yet you DO need a way to stop a user being able to repeatedly press a button on your UI that generates an API call, which would cause undesired effects (not least, repeated API calls hammering your front end and running down your user’s data allowance).

This article has the full code included in a repo link at the bottom, but there is certainly some scope for looking at how to produce the desired result as in the animated GIFs as below in a step-by-step tutorial.

I’ve decided to NOT include a demo of how to use a base view controller for this. Why? Didn’t you know that you’re not supposed to be able to do this? There must (always) be a better way. I hope this article helps you out…

Difficulty: Easy | Normal | Challenging

Prerequisites:

  • Some Swift experience, especially in the arena of API calls

Terminology

--

--