Zipping and unzipping files in your Swift app

Introducing Zip, an iOS framework for working with Zip files.

One of my favourite Objective C frameworks is SSZipArchive - it’s a very useful wrapper on top of minizip, an open source C library for zipping and unzipping files.

Last year I released a couple of Swift frameworks to help with phone number parsing and more general localization. For my first project of 2016, I wanted a different kind of challenge. Swift is super fun, powerful and elegant… until it needs to talk to C++ or C code. I wanted to try and create a Swift-native minizip wrapper that is lighter and takes advantage of what Swift has to offer (better type safety, progress closures, throwing errors etc).

Including a C library inside a Swift framework took plenty of xcode/podspec kung fu and I will write a more technical Medium post about that experience soon (UPDATE: It’s here).

Hello Zip

Zip is super simple and crazy fast. The easiest way to use it is via the zip and unzip quick functions. Both take local file paths as NSURLs, throw if an error is encountered and return an NSURL to the destination if successful. This is what they look like…

let unzipDirectory = try Zip.quickUnzipFile(filePath) //Unzip

let zipFilePath = try Zip.quickZipFiles([filePath], fileName: "archive") //Zip

For more advanced usage, Zip has functions that let you set custom destination paths, work with password protected zips and use a progress handling closure too.

Check it out on: