[swift4] ダウンロードしたzipを解凍するSSZipArchive実装方法
ダウンロードしたzipを解凍するSSZipArchive実装方法は以下の通り
SSZipArchiveはzipファイルへの圧縮・解凍ができるライブラリ
https://github.com/ZipArchive/ZipArchive
目次
podファイル作成
podが使用できる環境を準備してからプロジェクトが保存してあるフォルダに移動してから
pod init
コマンドでpodファイルを作成
作成してできたpodファイルに以下のコードを追記
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'プロジェクト名' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for textCollection
pod 'SSZipArchive'
target 'textCollectionTests' do
inherit! :search_paths
# Pods for testing
end
target 'textCollectionUITests' do
inherit! :search_paths
# Pods for testing
end
end
podインストール
コンソールでpodファイルが保存してあるフォルダに移動し、
pod install
コマンドを実行
SSZipArchiveの実装
pod installが正常に終了すると、workspaceファイルができるので、xcodeで開く
以下のコードで圧縮解凍ができる
import SSZipArchive
// Create
SSZipArchive.createZipFile(atPath: <#T##String#>, withContentsOfDirectory: <#T##String#>)
// Create with password
SSZipArchive.createZipFile(atPath: <#T##String#>, withContentsOfDirectory: <#T##String#>, withPassword: <#T##String?#>)
// Unzip
SSZipArchive.unzipFile(atPath: <#T##String#>, toDestination: <#T##String#>)
// Unzip with Password
do {
try SSZipArchive.unzipFile(atPath: <#T##String#>, toDestination: <#T##String#>, overwrite: <#T##Bool#>, password: <#T##String?#>)
}catch (let error) {
print(error)
}
// Unzip and Delete zip file
SSZipArchive.unzipFile(atPath: <#T##String#>, toDestination: <#T##String#>,
progressHandler: { _,_,_,_ in },
completionHandler: { _,_,_ in
try! FileManager.default.removeItem(atPath: <#T##String#>)
})
それぞれのPathはString型となる
Pingback: [swift4] daeファイルをインターネットからダウンロードしてScenekitで配置 | BlueBear I/O