Rurom
Rurom

Reputation: 253

Parsing JSON Alamofire 4.request

I have an old piece of code with Alamofire request:

func downloadItemDetails (completed:DownloadComplete) {
    let url = _itemUrl!
    Alamofire.request(.GET, url).responseJSON { (request:NSURLRequest?, response:HTTPURLResponse?, result:Result<AnyObject>) -> Void in
        print(result.value.debugDescription)
    }
}

How should i change the code to make it work with Alamofire 4 and Swift 3?

p.s. I know about the changes NSURLRequest -> URLRequest and NSHTTPURLResponse -> HTTPURLResponse, also i have read Alamofire 4.0 Migration Guide, but it does not helped me.

Upvotes: 1

Views: 178

Answers (1)

Rurom
Rurom

Reputation: 253

After detailed understanding of the Alamofire migration documentation i have already solved the issue by myself:

func downloadItemDetails (completed:DownloadComplete) {

    let url = _itemUrl!
    Alamofire.request(url, encoding: JSONEncoding.default).responseJSON { response in
        debugPrint(response)
    }
}

Thank you for attention. I hope it will help someone.

Upvotes: 1

Related Questions