Using this block, my App is crashing everytime it tries to
CGImageDestinationFinalize(gifDest!)
block
func createGIF(with images: [CGImage], data: Data, loopCount: Int, frameDelay: Double) -> Data {
print("()createGIF.HandHistoryTableVC")
let gifDest = CGImageDestinationCreateWithData(data as! CFMutableData, kUTTypeGIF, images.count, nil)
let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: loopCount]]
CGImageDestinationSetProperties(gifDest!, fileProperties as CFDictionary?)
let frameProperties = [(kCGImagePropertyGIFDictionary as String): [(kCGImagePropertyGIFDelayTime as String): frameDelay]]
for img in images {
CGImageDestinationAddImage(gifDest!, img, frameProperties as CFDictionary?)
}
print("GIF in Progress")
CGImageDestinationFinalize(gifDest!)
print("gifMade")
return data;
}
Error Report
I'm lost to the reason for this crash. All research about "Thread 1: signal SIGABRT" seems to say it's a connection problem, but my whole App works fine if i comment out the CGImageDestinationFinalize()
func createGIF(with images: [CGImage], data: CFMutableData, loopCount: Int, frameDelay: Double) -> Data {
print("()createGIF.HandHistoryTableVC")
let gifDest = CGImageDestinationCreateWithData(data, kUTTypeGIF, images.count, nil)
let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: loopCount]]
CGImageDestinationSetProperties(gifDest!, fileProperties as CFDictionary?)
let frameProperties = [(kCGImagePropertyGIFDictionary as String): [(kCGImagePropertyGIFDelayTime as String): frameDelay]]
for img in images {
CGImageDestinationAddImage(gifDest!, img, frameProperties as CFDictionary?)
}
print("GIF in Progress")
CGImageDestinationFinalize(gifDest!)
print("gifMade")
return data as Data;
}
with CFMutableData initializer
CFDataCreateMutable(kCFAllocatorDefault, 0)
solved this issue.