gpt4 book ai didi

ios - 未调用调度组功能 - 如何使用调度组?

转载 作者:行者123 更新时间:2023-11-28 12:40:49 26 4
gpt4 key购买 nike

我有几个函数可以从 firebase 检索数据。我希望事件指示器一直旋转,直到检索到所有数据。

我的问题是,这些功能甚至都没有启动。为了搜索错误,我输入了未调用的打印语句。

这是我的代码:

override func viewDidLoad() {
super.viewDidLoad()
loadingActInd.hidesWhenStopped = true
self.loadingActInd.startAnimating()

let group = dispatch_group_create()

dispatch_group_enter(group)
func loadTweetComplete() {
dispatch_group_leave(group)
}

dispatch_group_enter(group)
func loadEventsComplete() {
dispatch_group_leave(group)
}

dispatch_group_notify(group, dispatch_get_main_queue()) {
self.loadingActInd.stopAnimating()
print("deejayTweetsDictionary = \(deejayTweetsDictionary)")
print("finished executing")
}

}

func loadTweetComplete(completionHandler: () -> ()) {

print("TEST")

deejayTweetsDictionary.removeAll()

let usersRef = firebase.child("DeejayTweets").child(passedDJ.objectId)
usersRef.observeSingleEventOfType(.Value, withBlock: { snapshot in

if snapshot.exists() {

deejayTweetsDictionary.removeAll()

let sorted = (snapshot.value!.allValues as NSArray).sortedArrayUsingDescriptors([NSSortDescriptor(key: "date",ascending: false)])

for element in sorted {

deejayTweetsDictionary.append(element as! NSMutableDictionary)

}

}

completionHandler()
})
}

func loadEventsComplete(completionHandler: () -> ()) {

print("TEST")

eventDates.removeAll()

if passedDJ.objectId != nil {

let userRef = firebase.child("djBookings").child(passedDJ.objectId)

userRef.observeSingleEventOfType(.Value, withBlock: { (snapshot) in

if snapshot.exists() {

eventDates.removeAll()

let item = (snapshot.value as? NSMutableDictionary)!

let allValues = item.allValues
for element in allValues {

eventDates.append(element as! NSMutableDictionary)

}

}

completionHandler()
})

}
}

指标永远旋转,甚至 print("TEST") 语句都不会被调用。我究竟做错了什么?非常感谢您的帮助。

最佳答案

func loadTweetComplete() {
dispatch_group_leave(group)
}

定义一个(嵌套)函数。您想要的是调用以给定的完成处理程序作为参数的函数。使用将是的尾随闭包语法

loadTweetComplete {
dispatch_group_leave(group)
}

关于ios - 未调用调度组功能 - 如何使用调度组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39451274/

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