在swift中解压缩文件

imn*_*lly 8 objective-c unzip ios swift ssziparchive

如何在swift中解压缩文件?在Objective-C中,我使用了SSZipArchive,我喜欢它.如下面的代码所示.我怀疑如果我决定保留SSZipArchive,我将不得不将Objective-C文件桥接到我的Swift文件.是否有任何更新的第三方,或更好的Apple文档在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];
Run Code Online (Sandbox Code Playgroud)

Pet*_*inz 19

Swift 2(更新):

所以它适用于没有错误的我:

  1. 在这里下载/克隆库:ssziparchive
  2. 将目录"SSZipArchive"复制到项目(拖放)并选择"创建组"
  3. 将库包含到Project Swift-ObjC Bridge(xxxx-Bridge-Header.h)中

    #import"SSZipArchive.h"

  4. 链接库"libz.tbd" - iOS的一部分

    (项目 - >构建阶段 - >使用库链接二进制 - > +)

  5. 准备压缩/解压缩

  • 我正在使用cocoapod添加SSZipArchive,我在所有gzip引用上都出错了.我将libz.dylib添加到pod和项目的目标但仍然有错误.有任何想法吗?@screenworker (3认同)

Nat*_*ook 2

如果您正在使用 UIKit 或 AppKit 中的任何一个,则您已经在使用 Swift-ObjC 桥接器。不用担心,只需使用您熟悉和喜爱的图书馆即可!

let zipPath = globalFileStrucure.stringByAppendingPathComponent("zipfile.zip")
data.writeToFile(zipPath, options: nil, error: &error)

let unZipped = SSZipArchive.unzipFileAtPath(zipPath, toDestination: globalFileStrucure)
Run Code Online (Sandbox Code Playgroud)