Dispatch group not working properly in iOS 13

let dispatchGroup = DispatchGroup()

for _ in 1...views.count { dispatchGroup.enter() }

DispatchQueue.main.asyncAfter(deadline: .now() + delay) {

for (index, view) in views.enumerated() {

view.alpha = initialAlpha

view.animate(animations: animations,

reversed: reversed,

initialAlpha: initialAlpha,

finalAlpha: finalAlpha,

delay: Double(index) * animationInterval,

duration: duration,

usingSpringWithDamping: dampingRatio,

initialSpringVelocity: velocity,

options: options,

completion: { dispatchGroup.leave() })

}

}

dispatchGroup.notify(queue: .main) {

completion?()

}

Replies

Could you explain what "not working properly in iOS 13" mean ?


  • What do you expect ?
  • What do you get ?


Environment ?

  • Version of XCode
  • Simulator or device ?

Please provide more information on your code

  • delay value ?
  • how are animations defined, as well as all the other parameters

In iOS 13 completioner handler didn't call and gives crash. Nothing printed on console.
Xcode 11.1, Simulator iPhone 11 Pro

I formatted to more easily reference


let dispatchGroup = DispatchGroup()
        for _ in 1...views.count { dispatchGroup.enter() }
        DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
            for (index, view) in views.enumerated() {
                view.alpha = initialAlpha
                view.animate(animations: animations,
                             reversed: reversed,
                             initialAlpha: initialAlpha,
                             finalAlpha: finalAlpha,
                             delay: Double(index) * animationInterval,
                             duration: duration,
                             usingSpringWithDamping: dampingRatio,
                             initialSpringVelocity: velocity,
                             options: options,
                             completion: { dispatchGroup.leave() })
            }
        }
      
        dispatchGroup.notify(queue: .main) {
            completion?()
        }


Which completion does not get called ? Line 20 ?

If so, where is this completion defined ?

Were you able to find a solution?
I am having a similar issue where the app freezes when I show an AlertController inside a dispatch_group, only happens when using Xcode11.