dispatch_group_leave在swift中崩溃

时间:2015-05-27 04:25:48

标签: ios swift closures health-kit

这种情况很少发生。这是堆栈跟踪的最后一行:

0  libdispatch.dylib              0x0000000197a85a9c dispatch_group_leave + 48

dispatch_group_leave在一个完整的闭包中被调用,它被调用如下:

  dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
                { () -> Void in
                    let query = HKStatisticsCollectionQuery(quantityType: quantityType,
                        quantitySamplePredicate: nil,
                        options: statisticOptions,
                        anchorDate: anchorDate,
                        intervalComponents: interval)
                    query.initialResultsHandler = {

                        complete()

因此我们调度到后台线程,运行HKStatisticsCollectionQuery,然后调用一个名为complete的函数参数闭包。内部完成是调用dispatch_group_leave并发生崩溃的地方。

任何想法都非常感谢! 谢谢!

2 个答案:

答案 0 :(得分:16)

如果package main import( "fmt" "net/http" ) func main() { http.HandleFunc("/pattern", resolve) http.ListenAndServe(":8080", nil) } func resolve(w http.ResponseWriter, r * http.Request) { fmt.Println(r.URL.Host) } 呼叫未与dispatch_group_leave保持平衡,则可能会发生崩溃。

答案 1 :(得分:0)

在最坏的情况下,如果要检查值的数量,请输入补丁

            let count = self.groupExecuting.debugDescription.components(separatedBy: ",").filter({$0.contains("count")}).first!.components(separatedBy: CharacterSet.decimalDigits.inverted).filter({Int($0) != nil})