Alamofire:.GET中的表达类型不明确

时间:2015-12-04 01:24:12

标签: ios xcode swift alamofire

我正在尝试使用Alamofire框架进行简单下载。就在我将一个代码粘贴到我的Project(swift 2)中时,我在这个Alamofire代码中出现了这个错误:

Alamofire.download(.GET, "https://httpbin.org/stream/100", destination: destination)
            .progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
                print(totalBytesRead)

                // This closure is NOT called on the main queue for performance
                // reasons. To update your ui, dispatch to the main queue.
                dispatch_async(dispatch_get_main_queue()) {
                    print("Total bytes read on main queue: \(totalBytesRead)")
                }
            }
            .response { _, _, _, error in
                if let error = error {
                    print("Failed with error: \(error)")
                } else {
                    print("Downloaded file successfully")
                }
        }

at .GET请求 我已经尝试通过以下方式修复它:

不是.GET而是Alamofire.Method.GET,但没有成功......

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:1)

我使用了错误的路径目录,问题是当我想使用自己的路径下载文件时,我必须像这样使用它:

Alamofire.download(.GET, "https://httpbin.org/stream/100") { temporaryURL, response in
    let fileManager = NSFileManager.defaultManager()
    let directoryURL = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
    let pathComponent = response.suggestedFilename

    return directoryURL.URLByAppendingPathComponent(pathComponent!)
}

答案 1 :(得分:0)

你安装了Alamofire吊舱吗?

如果是这样,请确保您已将import Alamofire添加到文件顶部。