我有几个函数可以从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")
语句。我究竟做错了什么?非常感谢帮助。
答案 0 :(得分:2)
func loadTweetComplete() {
dispatch_group_leave(group)
}
定义一个(嵌套)函数。你想要的是调用 以给定的完成处理程序作为参数运行。 使用将是
的尾随闭包语法loadTweetComplete {
dispatch_group_leave(group)
}