With the service I'm working with, most of the responses are in XML, but a few are plain text. What's the best way to set that up?
Currently I have this:
// Root should return plain text, don't try to transform it
configureTransformer("/") { (content: String, entity) -> String? in
return content
}
// Most data is XML
configureTransformer("**") { (content: NSData, entity) -> NSXMLDocument? in
return try? NSXMLDocument(data: content, options: 0)
}
configureTransformer("**/properties/*") {
(content: NSData, entity) -> String? in
return String(data: content, encoding: NSUTF8StringEncoding)
}
..but when I query the root URL, which will be plain text, I get an error because the NSData -> NSXMLDocument transformer can't be applied.
Edit: Maybe what I really want is to apply the XML transformer when the content-type is application/xml. Is there a way to do that?