 
         // Create a dispatch group to force synchronous behavior on an asynchronous method.
         let gifGroup = Group()
-        var dispatchError: Bool = false
         gifGroup.enter()
 
         var handledTimes: Double = 0

            handledTimes += 1
            guard let imageRef = image , error == nil else {
                print("An error occurred: \(String(describing: error)), image is \(String(describing: image))")
                dispatchError = true
                gifGroup.leave()
                return
            }



        // Wait for the asynchronous generator to finish.
        gifGroup.wait()
        
        CGImageDestinationSetProperties(destination, fileProperties as CFDictionary)
        
