I found WPZipArchive is more easy to use and install, using Cocoapods. Anyone who interested can read the guide below:
1) Open Terminal.app from your Mac Application/Utilities folder or from your Launchpad
2) Enter sudo gem update --system
into your Terminal to ensure your Ruby is up to date
3) Enter sudo gem install cocoapods
to install cocoapods (This process will likely take a few minutes, just wait it show Completed)
4) Enter pod setup
to setup the cocoapods (from here onward, you do not need to use sudo
command, use only pod
)
5) Launch Xcode and create a new project (If you do not have existing project created). Skip this step if you had a Xcode project created.
6) QUIT Xcode program. Yes, close your project and quit the Xcode program
7) Back to Terminal and enter cd Path/To/Folder/Containing/YourProject
replace this Path/To/Folder/Containing/YourProject with your own directory path
8) Enter pod init
9) Enter open -a Xcode Podfile
to open the podfile using Xcode program. The default Podfile looks like this:
platform :osx, '10.10'
use_frameworks!
target 'myprojectname' do
pod 'WPZipArchive', '0.0.1'
end
platform :osx, '10.10'
is specify the minimum deployment target, you can change to whatever you preferred.
10) Save and Close Podfile (Close Xcode too)
11) Back to Terminal and enter pod install
this is to install the WPZipArchive, this will take few minutes.
12) You are done installing WPZipArchive.
Launch Xcode Project:
IMPORTANT: From now on, you must launch your Xcode project using the .xcworkspace NOT .xcodeproj
On the ViewController.swift or any .swift file you want to use zip or unzip method, just add import WPZipArchive like below:
import Cocoa
import WPZipArchive
To Zip a file, call method like this:
WPZipArchive.createZipFileAtPath(zipPath, withContentsOfDirectory: sampleDataPath)
To Unzip a file, call method like this:
WPZipArchive.unzipFileAtPath(zipPath, toDestination: unzipPath)
That's all and it work and easy to implement.
Enjoy zipping and unzipping