AlamofireJsonToObjects是一个Alamofire扩展,它可以把JSON响应数据转换成使用EVReflection的Swift对象。
示例:
class WeatherResponse: EVObject { var location: String? var three_day_forecast: [Forecast] = [Forecast]()}class Forecast: EVObject { var day: String? var temperature: NSNumber? var conditions: String?}class AlamofireJsonToObjectsTests: XCTestCase { func testResponseObject() { let URL = "https://raw.githubusercontent.com/evermeer/AlamofireJsonToObjects/master/AlamofireJsonToObjectsTests/sample_json" Alamofire.request(.GET, URL, parameters: nil) .responseObject { (response: WeatherResponse?, error: NSError?) in // That was all... You now have a WeatherResponse object with data } waitForExpectationsWithTimeout(10, handler: { (error: NSError!) -> Void in XCTAssertNil(error, "\(error)") }) }}
评论