问题
This happens very rarely. Here is the last line of the stack trace:
0 libdispatch.dylib 0x0000000197a85a9c dispatch_group_leave + 48
dispatch_group_leave is called in a complete closure which is invoked like this:
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()
So we dispatch to a background thread, run a HKStatisticsCollectionQuery, and then call a function parameter closure called complete. Inside complete is where the dispatch_group_leave is called and the crash happens.
Any ideas are most appreciated! Thanks!
回答1:
If dispatch_group_leave
call isn't balanced with dispatch_group_enter
then crash may happen.
回答2:
In worst case if you want to chek the count of number of values enter You can do this by following patch
let count = self.groupExecuting.debugDescription.components(separatedBy: ",").filter({$0.contains("count")}).first!.components(separatedBy: CharacterSet.decimalDigits.inverted).filter({Int($0) != nil})
来源:https://stackoverflow.com/questions/30473158/dispatch-group-leave-crash-in-swift