A simple pod to connect Decodable
to Alamofire
.
Assuming you have a decodable struct called Post
(check out Post.swift in the example project), then you can just use responseDecodable
to return you one (or a list) of them, like this:
Alamofire.request("https://jsonplaceholder.typicode.com/posts/1").responseDecodable { (response: DataResponse<Post>) in
switch response.result {
case .success(let post):
print("Recieved post: \(post)")
case .failure(let error):
print("Failed with error: \(error)")
}
}
Alamofire-Decodable requires iOS 9.0, Swift 3 and Xcode 8.
To run the example project, clone the repo and run the project in the Example folder.
Alamofire-Decodable is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Alamofire-Decodable"
Sam Dean, [email protected]
Alamofire-Decodable is available under the MIT license. See the LICENSE file for more info.