I made a game in Swift but I need to download .zip files on my website, and use the content (images) in game. Actually, I download the .zip file and store it in documents, and I need to unzip the file into the same documents folder.
I tried marmelroy's Zip, iOS 9 Compression module and tidwall's DeflateSwift but none of these worked. It could be good if it was compatible with iOS 8.
Using this library you can use this line: let unzipDirectory= try Zip. quickUnzipFile(filePath) //to unZip your folder. If you want more help , check the repository.
Decompressing a zipped file or folderFind the file you want to decompress, right-click it, and choose Extract All. In the dialog box that appears, to choose the destination for the decompressed files, click Browse.... You can also check the option Show extracted files when complete. Click Extract.
Open Xcode and select Open Another Project or File, Open. Open the folder you unzipped from your Dropsource download and locate the file with “. xcodeproj” extension in the root directory. Select the file and click Open.
I recently released a Swift native framework that allows you to create, read and update ZIP archive files: ZIP Foundation.
It internally uses libcompression for great compression performance.
Unzipping a file is basically just one line:
try fileManager.unzipItem(at: sourceURL, to: destinationURL)
A full example with some context would look like this:
let fileManager = FileManager()
let currentWorkingPath = fileManager.currentDirectoryPath
var sourceURL = URL(fileURLWithPath: currentWorkingPath)
sourceURL.appendPathComponent("archive.zip")
var destinationURL = URL(fileURLWithPath: currentWorkingPath)
destinationURL.appendPathComponent("directory")
do {
try fileManager.createDirectory(at: destinationURL, withIntermediateDirectories: true, attributes: nil)
try fileManager.unzipItem(at: sourceURL, to: destinationURL)
} catch {
print("Extraction of ZIP archive failed with error:\(error)")
}
The README on GitHub contains more information. All public methods also have full documentation available via Xcode Quick Help.
I also wrote a blog post about the performance characteristics here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With