Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ZIPFoundation basic code
import Foundation
import ZIPFoundation
let fileManager = FileManager()
let currentWorkingPath = fileManager.currentDirectoryPath
var sourceURL = URL(fileURLWithPath: currentWorkingPath)
sourceURL.appendPathComponent("file.txt")
var destinationURL = URL(fileURLWithPath: currentWorkingPath)
destinationURL.appendPathComponent("archive.zip")
do {
try fileManager.zipItem(at: sourceURL, to: destinationURL)
} catch {
print("Creation of ZIP archive failed with error:\(error)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment