(WP/S)ZipArchive progress/completion 处理程序输入 Swift
(WP/S)ZipArchive progress/completion handler type in Swift
我正在尝试使用 ZIP 库 WPZipArchive which is a fork of ZipArchive aka SZipArchive,但 unzipFileAtPath:toDestination:overwrite:password:progressHandler:completionHandler
(phew) 函数有问题。
WPZipArchive.h#L35-L40
我在 Swift 中编程,我在为进度和完成处理程序编写处理程序时遇到问题
例如如何创建 ((String!, unz_file_info, Int, Int)->Void)!
处理程序?
一些尝试:
WPZipArchive.unzipFileAtPath(help, toDestination: temp, progressHandler: (entry:String!, info:unz_file_info, current:Int, total:Int) {
}){ (path:String!, succeeded:Bool, error:NSError!) in
}
出现错误
.../ViewController.swift:45:142: Cannot convert value of type '() ->
()' to expected argument type '(entry: String!, info: unz_file_info,
current: Int, total: Int)' (aka '(entry:
ImplicitlyUnwrappedOptional, info: unz_file_info_s, current:
Int, total: Int)')
这个修改似乎有效:)
WPZipArchive.unzipFileAtPath(help, toDestination: temp, progressHandler: {(entry:String!, info:unz_file_info, current:Int, total:Int) in
}){ (path:String!, succeeded:Bool, error:NSError!) in
}
我在这里看不到函数名称,但是有两个处理程序(闭包)进度处理程序和完成处理程序。我不确定哪个叫
((String!, unz_file_info, Int, Int)->Void)!
func foo(completionHandler: (String!, unz_file_info, Int, Int)->Void){
//do whatever you need to
completionHandler("this is a string", <object of type unz_file_info>, 1, 2)
}
或者,如果您尝试将工作与来自处理程序的数据一起使用,您将实施它
foo(completionHandler: {
(w:String!, x:unz_file_info, y:Int, z:Int) in
print(w)
print(x)
print(y)
print(z)
})
您可以将其他参数放在首位,有关闭包的更多信息,请参阅:
https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html
我正在尝试使用 ZIP 库 WPZipArchive which is a fork of ZipArchive aka SZipArchive,但 unzipFileAtPath:toDestination:overwrite:password:progressHandler:completionHandler
(phew) 函数有问题。
WPZipArchive.h#L35-L40
我在 Swift 中编程,我在为进度和完成处理程序编写处理程序时遇到问题
例如如何创建 ((String!, unz_file_info, Int, Int)->Void)!
处理程序?
一些尝试:
WPZipArchive.unzipFileAtPath(help, toDestination: temp, progressHandler: (entry:String!, info:unz_file_info, current:Int, total:Int) {
}){ (path:String!, succeeded:Bool, error:NSError!) in
}
出现错误
.../ViewController.swift:45:142: Cannot convert value of type '() -> ()' to expected argument type '(entry: String!, info: unz_file_info, current: Int, total: Int)' (aka '(entry: ImplicitlyUnwrappedOptional, info: unz_file_info_s, current: Int, total: Int)')
这个修改似乎有效:)
WPZipArchive.unzipFileAtPath(help, toDestination: temp, progressHandler: {(entry:String!, info:unz_file_info, current:Int, total:Int) in
}){ (path:String!, succeeded:Bool, error:NSError!) in
}
我在这里看不到函数名称,但是有两个处理程序(闭包)进度处理程序和完成处理程序。我不确定哪个叫
((String!, unz_file_info, Int, Int)->Void)!
func foo(completionHandler: (String!, unz_file_info, Int, Int)->Void){
//do whatever you need to
completionHandler("this is a string", <object of type unz_file_info>, 1, 2)
}
或者,如果您尝试将工作与来自处理程序的数据一起使用,您将实施它
foo(completionHandler: {
(w:String!, x:unz_file_info, y:Int, z:Int) in
print(w)
print(x)
print(y)
print(z)
})
您可以将其他参数放在首位,有关闭包的更多信息,请参阅: https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html