Created
November 18, 2015 17:29
-
-
Save anonymous/b87d3e7908cfa5e02ec6 to your computer and use it in GitHub Desktop.
Fuzi Alamofire Response serializer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Request { | |
public static func XMLResponseSerializer() -> ResponseSerializer<XMLDocument, NSError> { | |
return ResponseSerializer { request, response, data, error in | |
guard error == nil else { return .Failure(error!) } | |
guard let validData = data else { | |
let failureReason = "Data could not be serialized. Input data was nil." | |
let error = Error.errorWithCode(.DataSerializationFailed, failureReason: failureReason) | |
return .Failure(error) | |
} | |
do { | |
let XML = try XMLDocument(data: validData) | |
return .Success(XML) | |
} catch { | |
return .Failure(error as NSError) | |
} | |
} | |
} | |
public func responseXMLDocument(completionHandler: Response<XMLDocument, NSError> -> Void) -> Self { | |
return response(responseSerializer: Request.XMLResponseSerializer(), completionHandler: completionHandler) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment