Search code examples
iosxcodeswiftalamofire

Alamofire : Type of expression is ambiguous in .GET


I'm trying to make a simple download using the Alamofire framework. Just when I pasted a code for download into my Project (swift 2), I get this error in this Alamofire code:

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 request I've already tried to fix it by :

not .GET but Alamofire.Method.GET , and no success...

Can someone help please ?


Solution

  • I used the wrong path directory, the problem is that when I want to use my own path to downloaded file, I have to use it like this:

    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!)
    }