Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert response.body from Vapor to String in Swift 3?

Tags:

vapor

I'm using Vapor to try to get an XML file from another server, the problem is I don't know how to convert the response body to a swift String.

let bikesResponse = try drop.client.get("http://www.c-bike.com.tw/xml/stationlistopendata.aspx")

let bodyBytes = bikesResponse.body
let string = String(bytes) // <-- WHAT DO I DO HERE?

Thanks

like image 315
Joseph Williamson Avatar asked Jan 28 '17 04:01

Joseph Williamson


1 Answers

Ah, ok I figured it out eventually.

let bikesResponse = try drop.client.get("http://www.c-bike.com.tw/xml/stationlistopendata.aspx")

if let bodyBytes = bikesResponse.body.bytes {

    let string = String(bytes: bodyBytes, encoding: String.Encoding.utf8) {

}
like image 107
Joseph Williamson Avatar answered Dec 17 '22 09:12

Joseph Williamson