[swift] 파일 압축 해제하기

이번에는 Swift 언어를 사용하여 파일을 압축 해제하는 방법에 대해 알아보겠습니다.

파일 압축 해제하기

Swift에서 파일을 압축 해제하기 위해서는 ZipArchive라이브러리를 사용할 수 있습니다. 먼저 ZipArchive를 프로젝트에 추가해야 합니다. CocoaPods를 사용한다면 Podfile에 아래와 같이 추가하고 pod install 명령어를 실행하세요.

platform:ios, '9.0'
use_frameworks!

target 'YourTarget' do
    pod 'ZipArchive'
end

그리고 ZipArchive를 import 해주세요.

import SSZipArchive

이제 파일을 압축 해제할 준비가 되었습니다. 압축파일의 경로와 압축이 해제될 디렉토리 경로를 지정해주면 됩니다.

let zipFilePath = "path/to/your/zipfile.zip"
let destinationPath = "path/to/destination/folder"

SSZipArchive.unzipFile(atPath: zipFilePath, toDestination: destinationPath)

위 코드를 실행하면 zipFile을 해제하여 destinationPath에 있는 폴더에 파일이 추출됩니다.

요약

이번 글에서는 Swift에서 파일 압축을 해제하는 방법에 대해 알아보았습니다. ZipArchive라이브러리를 사용하여 간단하게 파일을 압축 해제할 수 있습니다.