对于我正在处理的项目,我需要解压缩某些文件.为此,我找到了SSZipArchive库.我将其包含在Xcode 4.2中(右键单击Classes文件夹 - >将文件添加到项目中,在对话框中将"将项目复制到目标组的文件夹中" - 选中复选框).我包含libz库(我已尝试过libz和zlib1.2.5).我尝试编译,突然间我有20个错误:
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:311:1: error: expected identifier or '(' [1]
@class NSString, Protocol;
^
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:313:19: error: unknown type name 'NSString' [1]
FOUNDATION_EXPORT NSString *NSStringFromSelector(SEL aSelector);
^
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:314:44: error: unknown type name 'NSString' [1]
FOUNDATION_EXPORT SEL NSSelectorFromString(NSString *aSelectorName);
^
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:316:19: error: unknown type name 'NSString' [1]
FOUNDATION_EXPORT NSString *NSStringFromClass(Class aClass);
^
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:317:43: error: unknown type name 'NSString' [1]
FOUNDATION_EXPORT Class NSClassFromString(NSString *aClassName);
^
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:319:19: error: unknown type name 'NSString' [1]
FOUNDATION_EXPORT NSString *NSStringFromProtocol(Protocol *proto) NS_AVAILABLE(10_5, 2_0); …Run Code Online (Sandbox Code Playgroud) 如何在swift中解压缩文件?在Objective-C中,我使用了SSZipArchive,我喜欢它.如下面的代码所示.我怀疑如果我决定保留SSZipArchive,我将不得不将Objective-C文件桥接到我的Swift文件.是否有任何更新的第三方,或更好的Apple文档在Swift中解压缩文件?
NSString *zipPath = [self.globalFileStrucure stringByAppendingPathComponent:@"zipfile.zip"];
[data writeToFile:zipPath options:0 error:&error];
BOOL unZipped = 0;
unZipped = [SSZipArchive unzipFileAtPath:zipPath toDestination:self.globalFileStrucure];
Run Code Online (Sandbox Code Playgroud) 我有一个问题是将zips的libs添加到我的iPhone应用程序中.
我决定使用SSZipArchive.它使用minizip.
按照说明操作后:
1添加SSZipArchive.h,SSZipArchive.m和minizip
2将libz库添加到目标

我仍然得到错误:

未找到符号.
我尝试将-lz添加到Other Linker Flags并添加lybz.dylib,但它没有帮助.如果您知道如何让libz在这里工作,请告诉我.
解决:我没有使用文件夹,而是创建了一个黄色参考组,从包含中删除/ minizip /,现在一切正常.
let data = "InPractiseThisWillBeAReheallyLongString"
createDir()
let docsDir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let ourDir = docsDir.appendingPathComponent("ourCustomDir/")
let tempDir = ourDir.appendingPathComponent("temp/")
let unzippedDir = tempDir.appendingPathComponent("unzippedDir/")
let unzippedfileDir = unzippedDir.appendingPathComponent("unZipped.txt")
let zippedDir = tempDir.appendingPathComponent("Zipped.zip")
do {
try data.write(to: unzippedfileDir, atomically: false, encoding: .utf8)
let x = SSZipArchive.createZipFile(atPath: zippedDir.path, withContentsOfDirectory: unzippedfileDir.path)
var zipData: NSData! = NSData()
do {
zipData = try NSData(contentsOfFile: unzippedfileDir.path, options: NSData.ReadingOptions.mappedIfSafe)
//once I get a readable .zip file, I will be using this zipData in a multipart webservice
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用SSZipArchive框架解压缩文件.
let unzipper = SSZipArchive.unzipFileAtPath(String(document), toDestination: String(documentsUrl))
Run Code Online (Sandbox Code Playgroud)
这就是我目前正在尝试解压缩文件,这里是文件的路径:
unzipFileAtPath - Document at path: file:///private/var/mobile/Containers/Data/Application/94ADDB12-78A2-4798-856D-0626C41B7AC2/Documents/tSOUTrIayb.zip
false
我试图将它解压缩到这条路径:
NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first!
Run Code Online (Sandbox Code Playgroud)
不幸的是,它似乎没有工作,每次没有任何新的保存到我打印出来的文档目录中.我还打印了'unzipper'变量,它只是打印false,无论这意味着什么.
我找不到该框架的任何文档,所以我不完全确定如何使这个工作
我SSZipArchive用来提取文件的内容,我从互联网上下载并保存Documents.我正在下载的资源是zip文件的形式,我将在成功下载后解压缩.
@IBAction func downloadData(sender: UIButton)
{ if let myAudioDataFromUrl = NSData(contentsOfURL: audioUrl){
// after downloading your data you need to save it to your destination url
if myAudioDataFromUrl.writeToURL(destinationUrl, atomically: true) {
print("file saved")
printTimestamp()
let folderName = "Aspire Brochure"//audioUrl.lastPathComponent!.stringByReplacingOccurrencesOfString(".zip", withString: "")
let destination = documentsUrl.URLByAppendingPathComponent(folderName)
let fileManager = NSFileManager.defaultManager()
print("This is the folderName \(destinationUrl)")
print("This is the destination \(destination)")
let success = fileManager.fileExistsAtPath(destination.absoluteString) as Bool
if success == false {
do {
print("it is here")
try! …Run Code Online (Sandbox Code Playgroud) 我已经成功下载了该文件,但我无法保存该文件.因为我不断收到错误:
[SSZipArchive] Error: You don’t have permission to save the file “fileName” in the folder “Folder_Name”.
[SSZipArchive] Error: You don’t have permission to save the file “fileName” in the folder “__MACOSX”.
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激!
解压缩文件函数调用
ZipManager.unzipFile(atPath: filePath, delegate: self)
Run Code Online (Sandbox Code Playgroud)
ZipManager.swift
private static let documentsURL: URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
static func unzipFile(atPath path: String, delegate: SSZipArchiveDelegate)
{
let destFolder = "/Folder_Name"
let destPath = documentsURL.appendingPathComponent(destFolder, isDirectory: true)
let destString = destPath.absoluteString
if ( !FileManager.default.fileExists(atPath: destString) )
{
try! FileManager.default.createDirectory(at: destPath, …Run Code Online (Sandbox Code Playgroud) 我需要在swift中解压缩.epub文件以完全自己读取数据.我知道如何解析ePub的输出如果我能得到它(我在python中编写了一个工作示例),但SSZipArchive显然不会解压缩.epubs.但是,它确实可以在伪.zip文件上正常工作; 只有.epub是个问题.据我所知,毫无疑问,如果只是将人们指向那些在Objective-c中为你做的项目,并且有很多开销(我不明白或不需要) )这违背了我需要做的目的.以下是我目前的尝试.请注意,有问题的epub可以在以下链接(项目gutenberg)http://www.gutenberg.org/ebooks/158.epub.noimages找到,当我运行它时,print语句会发出:"true,true, true,false"(即文件和路径都存在,但不会解压缩):
import Foundation
class EpubExtractor: NSObject, SSZipArchiveDelegate {
init(fileName: String) {
fName = fileName
}
func getEpubInfo() {
var paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
let documentsDir = paths[0]
let zipPath = documentsDir.stringByAppendingString("/MyZipFiles") // My folder name in document directory
let fileManager = NSFileManager.defaultManager()
let success1 = fileManager.fileExistsAtPath(zipPath) as Bool
if success1 == false {
print("no directory")
do {
try! fileManager.createDirectoryAtPath(zipPath, withIntermediateDirectories: true, attributes: nil)
}
}
let archivePath = zipPath.stringByAppendingString("/emma.epub") // Sample folder is going …Run Code Online (Sandbox Code Playgroud)