-1

I am trying to run a function in the background thread to keep my app responsive to user actions but I am getting this error. -> 'Missing argument for parameter 'completion' in call'

What is the correct way to write to call this function to avoid the error?

func loadWebsites(completion: @escaping ((_ result: [Website]) -> Void)) {
    DispatchQueue.global(qos: .background).async {
        // Do some time consuming task in this background thread
        // Mobile app will remain to be responsive to user actions
        print("Performing time consuming task in this background thread")
        let url1 = URL(string: "\(self.nikeWebsite)")
        let request1 = URLRequest(url: url1!)
        let url2 = URL(string: "\(self.finishlineWebsite)")
        let request2 = URLRequest(url: url2!)
        let url3 = URL(string: "\(self.eastbayWebsite)")
        let request3 = URLRequest(url: url3!)

        let website1:Website = Bundle.main.loadNibNamed("Website", owner: self, options: nil)?.first as! Website
        if self.nikeWebsite == "https://firebasestorage.googleapis.com/v0/b/sneakem-2e19a.appspot.com/o/notavailable.png?alt=media&token=9f82b093-04c6-499d-bb80-f260708fb8b9" {
            website1.webView.navigationDelegate = self
        } else {
            website1.webView.load(request1)
            website1.webView.navigationDelegate = self
            website1.webView.allowsBackForwardNavigationGestures = true
        }

        let website2:Website = Bundle.main.loadNibNamed("Website", owner: self, options: nil)?.first as! Website
        if self.finishlineWebsite == "https://firebasestorage.googleapis.com/v0/b/sneakem-2e19a.appspot.com/o/notavailable.png?alt=media&token=9f82b093-04c6-499d-bb80-f260708fb8b9" {
            website2.webView.navigationDelegate = self
        } else {
            website2.webView.load(request2)
            website2.webView.navigationDelegate = self
            website2.webView.allowsBackForwardNavigationGestures = true
        }

        let website3:Website = Bundle.main.loadNibNamed("Website", owner: self, options: nil)?.first as! Website
        if self.eastbayWebsite == "https://firebasestorage.googleapis.com/v0/b/sneakem-2e19a.appspot.com/o/notavailable.png?alt=media&token=9f82b093-04c6-499d-bb80-f260708fb8b9" {
            website3.webView.navigationDelegate = self
        } else {
            website3.webView.load(request3)
            website3.webView.navigationDelegate = self
            website3.webView.allowsBackForwardNavigationGestures = true
        }

        DispatchQueue.main.async {
            completion([website1, website2, website3])
        }
    }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

0

Your signature for the completion parameter is incorrect.

Change:

func loadWebsites(completion: @escaping ((_ result: [Website]) -> Void)) {

to:

func loadWebsites(completion: @escaping ([Website]) -> Void) {
rmaddy
  • 314,917
  • 42
  • 532
  • 579