我正在尝试创建一个完成块,它可以在完成后执行另一个函数,在这种情况下,它是一个 tableview 重新加载。我得到错误:
'async' 产生 '()',而不是预期的上下文结果类型 'Bool'
这是功能:
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)
}
}
}
}
这是它的使用方式:
self.appendAllData(completion: { _ in
DispatchQueue.main.async { //error here: 'async' produces '()', not the expected contextual result type 'Bool'
self.detailTableView.reloadData()
}
})