Loader in iOS with swift 5

Loader in iOS with swift 5
April 26, 2020 No Comments Development,iOS Development Pushpendra Kumar

In this tutorial, I have explained to you that how you can create a loader in iOS with Swift 5. And you will learn this with the help of an extension. And for your kind information, I would like to tell you that we are not using any third-party library for loading. So, It’s a quite simple and easy way of loading. And this loader you can use for API calls for data fetching, or as per your requirement. So please follow the complete tutorial and learn deeply about loader integration in iOS with Swift 5.

Loader in iOS with swift 5

In Addition, This is the very simple way for showing loader on ViewController. We will do this with the help of UIActivityIndicatorView. So, Firstly create the UIViewController extension and write the following code in that. As it is suggesting in the video.

You use an UIActivityIndicatorView to indicate that something is going on. For example, If you are calling any API Service. Then it may take some time to respond with the expected data. At that time we can indicate to the user. That something is going on please wait.

func loader() -> UIAlertController {
        let alert = UIAlertController(title: nil, message: "Please wait...", preferredStyle: .alert)
        let loadingIndicator = UIActivityIndicatorView(frame: CGRect(x: 10, y: 5, width: 50, height: 50))
        loadingIndicator.hidesWhenStopped = true
        loadingIndicator.style = UIActivityIndicatorView.Style.large
        present(alert, animated: true, completion: nil)
        return alert
    func stopLoader(loader : UIAlertController) {
        DispatchQueue.main.async {
            loader.dismiss(animated: true, completion: nil)

Nice 😊😊😊 After that let see the use of this. And understand the use of this. 

    override func viewDidAppear(_ animated: Bool) {
        let loader =   self.loader()
        DispatchQueue.main.asyncAfter(deadline: .now() + 25) {
            self.stopLoader(loader: loader)

Great you have done with this. 

In Conclusion, This is the best and easiest way. I hope it is clear about How to create a loader in iOS with Swift 5 programming language. But if still, you have any confusion for the integration then you can visit on my YouTube video. In My Youtube video, I have explained deeply about Loader with the help of an extension. And also do not forget to subscribe to my YouTube channel. If you are looking more interesting topic then follow the below links and boost your skills.

About The Author
Pushpendra Kumar I am passionate about mobile application development and professional developer at Colour Moon Technologies Pvt Ltd (www.thecolourmoon.com). This website I have made so that I can meet with new challenges and can share here.

Leave a reply

Your email address will not be published. Required fields are marked *