AlamofireCodable: An extension to Alamofire which automatically converts JSON response data into swift objects using Codable.
This project is heavily inspired by the popular AlamofireObjectMapper.
AlamofireCodable can be added to your project using CocoaPods by adding the following line to your Podfile:
pod 'AlamofireCodable'ExampleTo run the example project, clone the repo, and run pod install from the Example directory first.
RequirementsXcode 9+ , Swift 4+
UsageGiven a URL which returns weather data in the following form:
{ 'data':{ 'location':'Toronto, Canada', 'three_day_forecast':[ { 'conditions':'Partly cloudy', 'day':'Monday', 'temperature':20 }, { 'conditions':'Showers', 'day':'Tuesday', 'temperature':22 }, { 'conditions':'Sunny', 'day':'Wednesday', 'temperature':28 } ] } }You can use the extension as the follows:
import AlamofireCodable let form = WeatherForm() Alamofire.request( form.url, method: HTTPMethod.get, parameters: form.parameters(), encoding: form.encoding(), headers: form.headers() ) .responseObject(keyPath: 'data',completionHandler: { (response: DataResponse<Weather>) in switch response.result { case .success(let object): debugPrint(' ,开题报告,开题报告