                     print("animated GIF file created at ", destinationURL)
                     
                     do {
-                        if let path = destinationURL.path {
-                            let attr : NSDictionary? = try NSFileManager.defaultManager().attributesOfItemAtPath(path)
-                            
-                            if let _attr = attr {
-                                print("FILE SIZE: ", NSByteCountFormatter.stringFromByteCount(Int64(_attr.fileSize()), countStyle: .File))
-                            }
+                        let path = destinationURL.path
+                        let attr : NSDictionary? = try FileManager.default.attributesOfItem(atPath: path) as NSDictionary
+                        
+                        if let _attr = attr {
+                            print("FILE SIZE: ", ByteCountFormatter.string(fromByteCount: Int64(_attr.fileSize()), countStyle: .file))
                         }
                     } catch {
                         print("Error: \(error)")
                     }
                     
-                    callback(data: NSData(contentsOfURL: destinationURL), error: nil)
+                    callback(try? Data(contentsOf: destinationURL), nil)
                 } else {
-                    callback(data: nil, error: self.errorFromString("Couldn't create the final image"))
+                    callback(nil, self.errorFromString("Couldn't create the final image"))
                 }
             }
         }

            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)
    }

     :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
     */
    open func generateGifFromImages(imagesArray:[UIImage], repeatCount: Int = 0, frameDelay: TimeInterval, destinationURL: URL, callback:@escaping (_ data: Data?, _ error: NSError?) -> ()) {
        
        DispatchQueue.global(qos: DispatchQoS.QoSClass.background).async {
            
            if let imageDestination = CGImageDestinationCreateWithURL(destinationURL as CFURL, kUTTypeGIF, imagesArray.count, nil) {
                
                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)
                }
                
                CGImageDestinationSetProperties(imageDestination, gifProperties)
