eclipse eclipse - 6 months ago 166
Swift Question

Swift convert NSError to String

Is there a way to convert an error of type NSError in swift to a string?

For example for something like this:

do {
try response.status(.OK).send(fileName: "html/index.html")
} catch {
response.status(.FAIL).send(error.CONVERT_TO_STRING)
}


.send() expects a string by default.

Answer

If your error is of type NSError, you can use error.localizedDescription to get the string.