You can also create the UIActivityIndicatorView in the Interface Builder. Just drag an Activity Indicator View onto the storyboard and set the properties. Be sure to check Hides When Stopped. Use an outlet to call startAnimating() and stopAnimating(). See this tutorial.
Remember that the default color of the LargeWhite style is white. So if you have a white background you can't see it, just change the color to black or whatever other color you want.
activityIndicator.color = UIColor.black
A common use case would be while a background task runs. Here is an example:
// start animating before the background task starts
activityIndicator.startAnimating()
// background task
DispatchQueue.global(qos: .userInitiated).async {
doSomethingThatTakesALongTime()
// return to the main thread
DispatchQueue.main.async {
// stop animating now that background task is finished
self.activityIndicator.stopAnimating()
}
}