gpt4 book ai didi

ios - 永远不会调用完成 block ?

转载 作者:可可西里 更新时间:2023-11-01 00:21:14 26 4
gpt4 key购买 nike

我们有一个函数,当它完成时,应该在它的完成 block 中调用另一个函数,但永远不会调用完成 block 中的任何内容。这是函数:

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

guard let movieDetails = self.movieDetailsData else {
// handle nil case
return;
}

if let posterImage = self.movieDetailsData?.poster {
self.posterArray.append(posterImage)
}

if let overview = self.movieDetailsData?.overview {
self.overviewArray.append(overview)
}

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

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

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

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

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

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

if let images = self.movieDetailsData?.images {
self.imageArray += images.backdropImages.map{ $0.filePath }
}
}

这是它的用法:

self.appendAllData(completion: { _ in
//Nothing inside here gets called
DispatchQueue.main.async {

print(self.movieDetailsData?.poster )

if let bgImage = self.movieDetailsData?.poster {
self.backgroundImage.sd_setImage(with: URL(string:"\(baseImageURL)\(bgImage)"))
print("background pic loaded")
self.backgroundImage.addBlurEffect()
}

self.detailTableView.reloadData()
}
})

完成 block 中没有任何内容被调用,知道如何解决这个问题吗?

最佳答案

我相信你需要在最后调用 completion() 来执行你的完成代码。

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

guard let movieDetails = self.movieDetailsData else {
// handle nil case
return;
}

if let posterImage = self.movieDetailsData?.poster {
self.posterArray.append(posterImage)
}

if let overview = self.movieDetailsData?.overview {
self.overviewArray.append(overview)
}

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

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

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

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

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

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

if let images = self.movieDetailsData?.images {
self.imageArray += images.backdropImages.map{ $0.filePath }
}

completion()
}

关于ios - 永远不会调用完成 block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42725036/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com