Unzip files in swift

imnilly picture imnilly · Oct 30, 2014 · Viewed 16.8k times · Source

How to go about unzipping a file in swift? In Objective-C, I used SSZipArchive and I loved it. As seen in the code below. I suspect if I decide to keep SSZipArchive, I will have to bridge an Objective-C file to my Swift file. Is there any updated third-party, or better yet Apple-Documentation to unzip a file in Swift?

NSString *zipPath = [self.globalFileStrucure stringByAppendingPathComponent:@"zipfile.zip"];

[data writeToFile:zipPath options:0 error:&error];

BOOL unZipped = 0;

unZipped = [SSZipArchive unzipFileAtPath:zipPath toDestination:self.globalFileStrucure];

Answer

Peter Kreinz picture Peter Kreinz · Mar 18, 2015

Swift 2 (Update):

So it works for me without Errors:

  1. download/clone the Library here: ssziparchive
  2. copy the Directory "SSZipArchive" to your Project (Drag&Drop) and select 'Create groups'
  3. include the library to your Project Swift-ObjC Bridge (xxxx-Bridge-Header.h)

    #import "SSZipArchive.h"

  4. link the Library "libz.tbd" - Part of iOS

    (Project -> Build Phases -> Link Binary With Libraries -> +)

  5. Ready to zip/unzip