      :param: frameDelay an delay in seconds between each frame
      :param: callback set a block that will get called when done, it'll return with data and error, both which can be nil
      */
-    public func generateGifFromImages(imagesArray imagesArray:[UIImage], repeatCount: Int = 0, frameDelay: NSTimeInterval, destinationURL: NSURL, callback:(data: NSData?, error: NSError?) -> ()) {
+    open func generateGifFromImages(imagesArray:[UIImage], repeatCount: Int = 0, frameDelay: TimeInterval, destinationURL: URL, callback:@escaping (_ data: Data?, _ error: NSError?) -> ()) {
         
-        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)) { () -> Void in
+        DispatchQueue.global(qos: DispatchQoS.QoSClass.background).async {
             
-            if let imageDestination = CGImageDestinationCreateWithURL(destinationURL, kUTTypeGIF, imagesArray.count, nil) {
+            if let imageDestination = CGImageDestinationCreateWithURL(destinationURL as CFURL, kUTTypeGIF, imagesArray.count, nil) {
                 
-                let frameProperties:CFDictionaryRef = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: frameDelay]]
-                let gifProperties:CFDictionaryRef = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: repeatCount]]
+                let frameProperties:CFDictionary = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: frameDelay]] as CFDictionary
+                let gifProperties:CFDictionary = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: repeatCount]] as CFDictionary
                 
                 for image in imagesArray {
-                    CGImageDestinationAddImage(imageDestination, image.CGImage!, frameProperties)
+                    CGImageDestinationAddImage(imageDestination, image.cgImage!, frameProperties)
                 }
                 
                 CGImageDestinationSetProperties(imageDestination, gifProperties)

            cmTimeArray.removeAll()
        }
        
        for (var t = 0; t < videoDuration; t++) {
            let tempInt = Int64(t)
            let tempCMTime = CMTimeMake(tempInt, asset.duration.timescale)
            let interval = Int32(framesInterval)
            
            for (var j = 1; j < framesInterval+1; j++) {
                let newCMtime = CMTimeMake(Int64(j), interval)
                let addition = CMTimeAdd(tempCMTime, newCMtime)
                cmTimeArray.append(NSValue(CMTime: addition))
            }
        }
    }

    private func errorFromString(string: String, code: Int = -1) -> NSError {
        let dict = [NSLocalizedDescriptionKey: string]
        return NSError(domain: "org.cocoapods.GIFGenerator", code: code, userInfo: dict)
    }

import AVFoundation


@objc open class GifGenerator: NSObject {
    
    var cmTimeArray:[NSValue] = []
    var framesArray:[UIImage] = []
