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

import AVFoundation


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

            cmTimeArray.removeAll()
        }
        
        for t in 0..<videoDuration {
            let tempInt = Int64(t)
            let tempCMTime = CMTimeMake(tempInt, asset.duration.timescale)
            let interval = Int32(framesInterval)
            
            
            for j in 1..<framesInterval+1 {
                let newCMtime = CMTimeMake(Int64(j), interval)
                let addition = CMTimeAdd(tempCMTime, newCMtime)
                cmTimeArray.append(NSValue(time: addition))
            }
        }
    }
    
    fileprivate func errorFromString(_ string: String, code: Int = -1) -> NSError {
        let dict = [NSLocalizedDescriptionKey: string]
        return NSError(domain: "org.cocoapods.GIFGenerator", code: code, userInfo: dict)
    }
