I would like to add the answer to Nicolau Giantcchi. The Top Shelf extension will work in the main thread, so using methods like UIImageJPEGRepresentation or UIImagePNGRepresentation sometimes stops the Top Shelf thread that prints this to the console:
Program terminated with exit code: 0
To fix this, you can wrap your code as follows:
DispatchQueue.main.sync { UIImageJPEGRepresentation(newImage, 0.8)!.writeToFile(filepath, atomically: true) let imageURL = NSURL(fileURLWithPath: filepath) if #available(tvOSApplicationExtension 11.0, *) { contentItem.setImageURL(imageURL, forTraits: .userInterfaceStyleLight) contentItem.setImageURL(imageURL, forTraits: .userInterfaceStyleDark) } else { contentItem.imageURL = imageURL } }
source share