Textgröße
Kontrast
While you could bridge to older C-libraries, the Swift community has created some fantastic, "Swifty" wrappers that make the process much safer.
import ZIPFoundation import Foundation let fileManager = FileManager.default let sourceURL = URL(fileURLWithPath: "/path/to/directory") let destinationURL = URL(fileURLWithPath: "/path/to/archive.zip") do { try fileManager.zipItem(at: sourceURL, to: destinationURL) print("Archive created successfully!") } catch { print("Creation failed with error: \(error)") } Use code with caution. Copied to clipboard Tips for Better Archiving siwt.zip
Here is a blog post covering how to handle ZIP archives in Swift using modern frameworks. Effortless Archiving: Master ZIP Files in Swift While you could bridge to older C-libraries, the
: If you only need to create a ZIP for uploading, you can actually use Apple’s NSFileCoordinator API without any third-party code. Quick Start: Zipping a Folder Effortless Archiving: Master ZIP Files in Swift :
How to easily create ZIP files in Swift without third-party dependencies