I trying out with SWXMLHash
and to mock a download from a website to parse, I created a file in the playground with the data. I got this as the response from URLSessionManager
Data looks similar to:
3c3f786d 6c207665 7273696f 6e3d2731 ...
But of course much longer.
I read it in as follows:
guard let fileURL = Bundle.main.url(forResource: "xmlData", withExtension: "")
else { fatalError("cannot load file")}
do {
let xmlData = try Data(contentsOf: fileURL, options: .mappedIfSafe)
} catch {
print(error)
}
This works I think, there is no error and if I print the data it returns 169735 bytes
.
Then I try to parse it (inside the do
block):
let xml = SWXMLHash.parse(xmlData)
print(xml)
This returns \n
, so no output.
SWXMLHash
provides a method that accepts a Data
object.
How can I get this to work?