目前我有一个从数据库中获取章节的功能。
func fetchChapters(completion: @escaping (_ chapters: [Chapter])->()) {
var chapters: [Chapter] = []
guard let novelID = novel?.nid else { return }
handle = DataService.shared.chapterRef.child(novelID).observe(.childAdded, with: { (snap) in
guard let chapter = Chapter(snap: snap) else { return }
chapters.append(chapter)
print("chapter arr count", chapters.count)
completion(chapters)
}, withCancel: nil)
}
此功能正常但我想要的是我想在从数据库下载所有章节后才调用完成。有没有办法实现。