Skip to content

Commit

Permalink
made compatible with Alamofire 5.0.0-rc2
Browse files Browse the repository at this point in the history
  • Loading branch information
Ozgur Vatansever committed Sep 23, 2019
1 parent 9411d27 commit 36236f5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
12 changes: 6 additions & 6 deletions AlamofireObjectMapper/AlamofireObjectMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ extension DataRequest {
let JSONObject = processResponse(request: request, response: response, data: data, keyPath: keyPath)

if let JSONObject = JSONObject,
let parsedObject = (try? Mapper<T>(context: context, shouldIncludeNilValues: false).map(JSONObject: JSONObject)){
let parsedObject = (try? Mapper<T>(context: context, shouldIncludeNilValues: false).map(JSONObject: JSONObject) as T) {
return parsedObject
} else {
let failureReason = "ObjectMapper failed to serialize response."
Expand All @@ -129,12 +129,12 @@ extension DataRequest {
- returns: The request.
*/
@discardableResult
public func responseObject<T: BaseMappable>(queue: DispatchQueue = .main, keyPath: String? = nil, mapToObject object: T? = nil, context: MapContext? = nil, completionHandler: @escaping (DataResponse<T>) -> Void) -> Self {
public func responseObject<T: BaseMappable>(queue: DispatchQueue = .main, keyPath: String? = nil, mapToObject object: T? = nil, context: MapContext? = nil, completionHandler: @escaping (AFDataResponse<T>) -> Void) -> Self {
return response(queue: queue, responseSerializer: DataRequest.ObjectMapperSerializer(keyPath, mapToObject: object, context: context), completionHandler: completionHandler)
}

@discardableResult
public func responseObject<T: ImmutableMappable>(queue: DispatchQueue = .main, keyPath: String? = nil, mapToObject object: T? = nil, context: MapContext? = nil, completionHandler: @escaping (DataResponse<T>) -> Void) -> Self {
public func responseObject<T: ImmutableMappable>(queue: DispatchQueue = .main, keyPath: String? = nil, mapToObject object: T? = nil, context: MapContext? = nil, completionHandler: @escaping (AFDataResponse<T>) -> Void) -> Self {
return response(queue: queue, responseSerializer: DataRequest.ObjectMapperImmutableSerializer(keyPath, context: context), completionHandler: completionHandler)
}

Expand Down Expand Up @@ -165,7 +165,7 @@ extension DataRequest {

if let JSONObject = processResponse(request: request, response: response, data: data, keyPath: keyPath){

if let parsedObject = try? Mapper<T>(context: context, shouldIncludeNilValues: false).mapArray(JSONObject: JSONObject){
if let parsedObject = try? Mapper<T>(context: context, shouldIncludeNilValues: false).mapArray(JSONObject: JSONObject) as [T] {
return parsedObject
}
}
Expand All @@ -185,7 +185,7 @@ extension DataRequest {
- returns: The request.
*/
@discardableResult
public func responseArray<T: BaseMappable>(queue: DispatchQueue = .main, keyPath: String? = nil, context: MapContext? = nil, completionHandler: @escaping (DataResponse<[T]>) -> Void) -> Self {
public func responseArray<T: BaseMappable>(queue: DispatchQueue = .main, keyPath: String? = nil, context: MapContext? = nil, completionHandler: @escaping (AFDataResponse<[T]>) -> Void) -> Self {
return response(queue: queue, responseSerializer: DataRequest.ObjectMapperArraySerializer(keyPath, context: context), completionHandler: completionHandler)
}

Expand All @@ -199,7 +199,7 @@ extension DataRequest {
- returns: The request.
*/
@discardableResult
public func responseArray<T: ImmutableMappable>(queue: DispatchQueue = .main, keyPath: String? = nil, context: MapContext? = nil, completionHandler: @escaping (DataResponse<[T]>) -> Void) -> Self {
public func responseArray<T: ImmutableMappable>(queue: DispatchQueue = .main, keyPath: String? = nil, context: MapContext? = nil, completionHandler: @escaping (AFDataResponse<[T]>) -> Void) -> Self {
return response(queue: queue, responseSerializer: DataRequest.ObjectMapperImmutableArraySerializer(keyPath, context: context), completionHandler: completionHandler)
}
}
Expand Down
36 changes: 18 additions & 18 deletions AlamofireObjectMapperTests/AlamofireObjectMapperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ class AlamofireObjectMapperTests: XCTestCase {
let URL = "https://raw.githubusercontent.com/tristanhimmelman/AlamofireObjectMapper/d8bb95982be8a11a2308e779bb9a9707ebe42ede/sample_json"
let expectation = self.expectation(description: "\(URL)")

_ = Alamofire.request(URL, method: .get).responseObject { (response: DataResponse<WeatherResponse>) in
_ = AF.request(URL, method: .get).responseObject { (response: AFDataResponse<WeatherResponse>) in
expectation.fulfill()

let mappedObject = response.result.value
let mappedObject = response.value

XCTAssertNotNil(mappedObject, "Response should not be nil")
XCTAssertNotNil(mappedObject?.location, "Location should not be nil")
Expand All @@ -78,10 +78,10 @@ class AlamofireObjectMapperTests: XCTestCase {
let weatherResponse = WeatherResponse()
weatherResponse.date = Date()

_ = Alamofire.request(URL, method: .get).responseObject(mapToObject: weatherResponse) { (response: DataResponse<WeatherResponse>) in
_ = AF.request(URL, method: .get).responseObject(mapToObject: weatherResponse) { (response: AFDataResponse<WeatherResponse>) in
expectation.fulfill()

let mappedObject = response.result.value
let mappedObject = response.value
print(weatherResponse)
XCTAssertNotNil(mappedObject, "Response should not be nil")
XCTAssertNotNil(mappedObject?.date, "Date should not be nil") // Date is not in JSON but should not be nil because we mapped onto an existing object with a date set
Expand All @@ -105,10 +105,10 @@ class AlamofireObjectMapperTests: XCTestCase {
let URL = "https://raw.githubusercontent.com/tristanhimmelman/AlamofireObjectMapper/2ee8f34d21e8febfdefb2b3a403f18a43818d70a/sample_keypath_json"
let expectation = self.expectation(description: "\(URL)")

_ = Alamofire.request(URL, method: .get).responseObject(keyPath: "data") { (response: DataResponse<WeatherResponse>) in
_ = AF.request(URL, method: .get).responseObject(keyPath: "data") { (response: AFDataResponse<WeatherResponse>) in
expectation.fulfill()

let mappedObject = response.result.value
let mappedObject = response.value

XCTAssertNotNil(mappedObject, "Response should not be nil")
XCTAssertNotNil(mappedObject?.location, "Location should not be nil")
Expand All @@ -131,10 +131,10 @@ class AlamofireObjectMapperTests: XCTestCase {
let URL = "https://raw.githubusercontent.com/tristanhimmelman/AlamofireObjectMapper/97231a04e6e4970612efcc0b7e0c125a83e3de6e/sample_keypath_json"
let expectation = self.expectation(description: "\(URL)")

_ = Alamofire.request(URL, method: .get).responseObject(keyPath: "response.data") { (response: DataResponse<WeatherResponse>) in
_ = AF.request(URL, method: .get).responseObject(keyPath: "response.data") { (response: AFDataResponse<WeatherResponse>) in
expectation.fulfill()

let mappedObject = response.result.value
let mappedObject = response.value

XCTAssertNotNil(mappedObject, "Response should not be nil")
XCTAssertNotNil(mappedObject?.location, "Location should not be nil")
Expand All @@ -157,10 +157,10 @@ class AlamofireObjectMapperTests: XCTestCase {
let URL = "https://raw.githubusercontent.com/tristanhimmelman/AlamofireObjectMapper/f583be1121dbc5e9b0381b3017718a70c31054f7/sample_array_json"
let expectation = self.expectation(description: "\(URL)")

_ = Alamofire.request(URL, method: .get).responseArray { (response: DataResponse<[Forecast]>) in
_ = AF.request(URL, method: .get).responseArray { (response: AFDataResponse<[Forecast]>) in
expectation.fulfill()

let mappedArray = response.result.value
let mappedArray = response.value

XCTAssertNotNil(mappedArray, "Response should not be nil")

Expand All @@ -183,11 +183,11 @@ class AlamofireObjectMapperTests: XCTestCase {
let URL = "https://raw.githubusercontent.com/tristanhimmelman/AlamofireObjectMapper/d8bb95982be8a11a2308e779bb9a9707ebe42ede/sample_json"
let expectation = self.expectation(description: "\(URL)")

_ = Alamofire.request(URL, method: .get).responseArray(keyPath: "three_day_forecast") { (response: DataResponse<[Forecast]>) in
_ = AF.request(URL, method: .get).responseArray(keyPath: "three_day_forecast") { (response: AFDataResponse<[Forecast]>) in

expectation.fulfill()

let mappedArray = response.result.value
let mappedArray = response.value

XCTAssertNotNil(mappedArray, "Response should not be nil")

Expand All @@ -208,11 +208,11 @@ class AlamofireObjectMapperTests: XCTestCase {
let URL = "https://raw.githubusercontent.com/tristanhimmelman/AlamofireObjectMapper/97231a04e6e4970612efcc0b7e0c125a83e3de6e/sample_keypath_json"
let expectation = self.expectation(description: "\(URL)")

_ = Alamofire.request(URL, method: .get).responseArray(keyPath: "response.data.three_day_forecast") { (response: DataResponse<[Forecast]>) in
_ = AF.request(URL, method: .get).responseArray(keyPath: "response.data.three_day_forecast") { (response: AFDataResponse<[Forecast]>) in

expectation.fulfill()

let mappedArray = response.result.value
let mappedArray = response.value

XCTAssertNotNil(mappedArray, "Response should not be nil")

Expand All @@ -235,10 +235,10 @@ class AlamofireObjectMapperTests: XCTestCase {
let URL = "https://raw.githubusercontent.com/tristanhimmelman/AlamofireObjectMapper/d8bb95982be8a11a2308e779bb9a9707ebe42ede/sample_json"
let expectation = self.expectation(description: "\(URL)")

_ = Alamofire.request(URL, method: .get).responseObject { (response: DataResponse<WeatherResponseImmutable>) in
_ = AF.request(URL, method: .get).responseObject { (response: AFDataResponse<WeatherResponseImmutable>) in
expectation.fulfill()

let mappedObject = response.result.value
let mappedObject = response.value

XCTAssertNotNil(mappedObject, "Response should not be nil")
XCTAssertNotNil(mappedObject?.location, "Location should not be nil")
Expand All @@ -261,10 +261,10 @@ class AlamofireObjectMapperTests: XCTestCase {
let URL = "https://raw.githubusercontent.com/tristanhimmelman/AlamofireObjectMapper/f583be1121dbc5e9b0381b3017718a70c31054f7/sample_array_json"
let expectation = self.expectation(description: "\(URL)")

_ = Alamofire.request(URL, method: .get).responseArray { (response: DataResponse<[ImmutableForecast]>) in
_ = AF.request(URL, method: .get).responseArray { (response: AFDataResponse<[ImmutableForecast]>) in
expectation.fulfill()

let mappedArray = response.result.value
let mappedArray = response.value

XCTAssertNotNil(mappedArray, "Response should not be nil")

Expand Down
4 changes: 2 additions & 2 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "Alamofire/Alamofire" "5.0.0-beta.6"
github "tristanhimmelman/ObjectMapper" ~> 3.4
github "Alamofire/Alamofire" "5.0.0-rc.2"
github "tristanhimmelman/ObjectMapper" ~> 3.5.1
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "Alamofire/Alamofire" "5.0.0-beta.6"
github "Alamofire/Alamofire" "5.0.0-rc.2"
github "tristanhimmelman/ObjectMapper" "3.5.1"

0 comments on commit 36236f5

Please sign in to comment.