Create a completion block that returns nothing but executes another function when completed?

SwiftyJD

I'm trying to create a completion block that can execute another function after its completed, in this case it's a tableview reload. I get the error :

'async' produces '()', not the expected contextual result type 'Bool'

This is the function:

  func appendAllData (completion: () -> Bool) {

    if self.movieDetailsData?.poster != nil {
      if let posterImage = self.movieDetailsData?.poster {
        self.posterArray.append(posterImage)
      }
    }
    if self.movieDetailsData?.overview != nil {
      if let overview = self.movieDetailsData?.overview {
        self.overviewArray.append(overview)
      }
    }

    if self.movieDetailsData?.releaseData != nil {
      if let releaseDate = self.movieDetailsData?.releaseData {
        self.releaseInfoArray.append(releaseDate)
      }
    }

    if self.movieDetailsData?.runtime != nil {
      if let runtime = self.movieDetailsData?.runtime {
        self.releaseInfoArray.append(String(describing: runtime))
      }
    }

    if self.movieDetailsData?.genre != nil {
      if let genre = self.movieDetailsData?.genre {
        if genre.isEmpty {
        } else {
          self.releaseInfoArray.append(genre[0].name)
        }
      }
    }

    if self.movieDetailsData?.budget != nil {
      if let budget = self.movieDetailsData?.budget {
        self.boxOfficeArray.append(budget)
      }
    }

    if self.movieDetailsData?.revenue != nil {
      if let revenue = self.movieDetailsData?.revenue {
        self.boxOfficeArray.append(revenue)
      }
    }

    if self.movieDetailsData?.homepage != nil {
      if let homepage = self.movieDetailsData?.homepage {
        self.homePageArray.append(homepage)
      }
    }

    if self.movieDetailsData?.images != nil {
      if let images = self.movieDetailsData?.images {

        let posters = images.backdropImages
        for poster in posters {

          self.imageArray.append(poster.filePath)
        }
      }
    }
  }

This is how it's used:

 self.appendAllData(completion: { _ in

  DispatchQueue.main.async { //error here: 'async' produces '()', not the expected contextual result type 'Bool'
    self.detailTableView.reloadData()
  }
})
Leo

Your completion closure signature is completion: () -> Bool but you used () -> (). Just change function parameter from completion: () -> Bool to completion: () -> Void or completion: () -> (). And you should follow njzk2's comment.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Function that executes after multiple completion block has finished

How to create function that returns nothing

$http promise executes success block even when service returns 404

ANY function returns nothing when the database is empty

For loop returns nothing when using function

Is it possible to call a block completion handler from another function in iOS?

RXJS concat: Does it execute already completed observables when another observable in the pipe executes again?

Promise executes then function before previous then execution is completed

return function in another child class from the same parent returns nothing

Function that returns another function executes the body of outer function on every call of the returned function

python function returns nothing

Return function returns nothing

UIActivityViewController completion handler is !completed when using AirDrop

R function runs, executes nothing (apparently)

onBeforeUnload creates prompt even when function returns nothing

Function with optional completion block in Swift

Why XMPP function returns nothing?

Laravel hasmany function returns nothing

void function returns nothing - C

Calling a stored function that returns nothing

unit test for a function that returns nothing

Does linux "rename" function call block until copy(when source and target in different disks) is completed

Create block from another block

IF block executes when the condition does not apply

How to test if a function gets called when another function executes in django test?

Function that only returns false returns nothing

How to know when a block has been completed

Should block handlers be nil out when completed?

Javascript call function after another function executes

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    pump.io port in URL

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  14. 14

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  15. 15

    How to use merge windows unallocated space into Ubuntu using GParted?

  16. 16

    flutter: dropdown item programmatically unselect problem

  17. 17

    Pandas - check if dataframe has negative value in any column

  18. 18

    Nuget add packages gives access denied errors

  19. 19

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  20. 20

    Generate random UUIDv4 with Elm

  21. 21

    Client secret not provided in request error with Keycloak

HotTag

Archive