ZipArchive

Swift 使用 ZipArchive 解/壓縮檔案

工作中有需要使用到壓縮與解壓縮 zip 檔案,原本 Mac 以為內建的壓縮功能就可以做到,如下:

https://developer.apple.com/documentation/compression

結果試了半天,也查了一堆資料,好像都無法做到。在查詢資料的過程中,也看到很多人推薦 ZipArchive,我也就用它來測試了。

https://github.com/ZipArchive/ZipArchive

ZipArchive 是 Objective-C 寫的專案,我是要用 Swift 去執行,底下記錄了詳細過程。如果對於 Swift 連結 Objective-C 想多了解一點,可參考這篇:Swift 連結 Swift、Objective-C、C++

ZipArchive 的 Github 專案上有教導如何安裝使用,因為我沒有使用其他安裝工具,所以我採取手動安裝,它主要方法有四:

  1. Add the SSZipArchive and minizip folders to your project.

  2. Add the libz and libiconv libraries to your target.

  3. Add the Security framework to your target.

  4. Add the following GCC_PREPROCESSOR_DEFINITIONS: HAVE_INTTYPES_H HAVE_PKCRYPT HAVE_STDINT_H HAVE_WZAES HAVE_ZLIB $(inherited).

 

底下逐一記錄過程。

重要度:
借我放一下廣告
訂閱 ZipArchive