我尝试从 ZipArchive
的这个函数中获取错误对象
guard ZipArchive.unzipFileAtPath(filePath as String,toDestination: folderPath as String,overwrite: true, password: nil,error: whatShouldGoHere) else
{
throw whatShouldGoHere
}
我的问题是如何从这个 unzipFileAtPath
Objective-C
函数中取回 whatShouldGoHere?
我注意到在 unzipFileAtPath
函数的定义中可以访问 NSError
对象到 whatShouldGoHere
参数
NSError *err = [NSError errorWithDomain:@"ZipArchiveErrorDomain" code:-1 userInfo:userInformation];
if (error) {
error = err;
}
最佳答案
我将使用这个库 ZipArchive向您展示如何通过调用 objective-c 函数获取错误对象。
在这个库中,它也具有上述相同的功能。
+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(NSString *)password error:(NSError **)error;
在 swift 2.1 中,你可以使用 Handling Errors Using Do-Catch获取错误对象。
do {
try SSZipArchive.unzipFileAtPath(filePath, toDestination: folderPath, overwrite: true, password: nil)
} catch {
print(error)
}
关于objective-c - 在 swift 端形式 objective-c 端出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34562702/