func createGIF(with images: [UIImage], loopCount: Int = 0, frameDelay: Double, callback: (data: NSData?, error: NSError?) -> ()) { let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: loopCount]] let frameProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: frameDelay]] let documentsDirectory = NSTemporaryDirectory() let url = NSURL(fileURLWithPath: documentsDirectory)?.URLByAppendingPathComponent("animated.gif") if let url = url { let destination = CGImageDestinationCreateWithURL(url, kUTTypeGIF, UInt(images.count), nil) CGImageDestinationSetProperties(destination, fileProperties) for i in 0..