【发布时间】:2015-09-10 10:33:26
【问题描述】:
我正在使用 Alamofire 库,我注意到他们使用这种语法
func download(method: Alamofire.Method, URLString: URLStringConvertible, headers: [String : String]? = default, #destination: Alamofire.Request.DownloadFileDestination) -> Alamofire.Request
这需要 4 个参数作为输入,但如果你去 documentation 调用他们使用以下方法的方法
Alamofire.download(.GET, "http://httpbin.org/stream/100") { temporaryURL, response in
let fileManager = NSFileManager.defaultManager()
if let directoryURL = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as? NSURL {
let pathComponent = response.suggestedFilename
return directoryURL.URLByAppendingPathComponent(pathComponent!)
}
return temporaryURL}
只需要 2 个参数(method: 和 URLString:)我认为参数 headers 是可选的,因为提供了 default 语句。
我不明白Destination 是如何处理的。
你能解释一下关闭是如何处理的吗?
为什么花括号在方法调用之后是打开的,而不是在 URLString param 之后的调用内部?
非常感谢您提供的任何帮助
马可
【问题讨论】:
-
查看 Swift 书中的"Trailing Closures"。
标签: xcode swift syntax closures alamofire