I was trying to translate the code from swift 2 to swift 4 and came across this error
Errors thrown from here are not handled
So I did this but now it tells me to return a string. Any idea how to do this?
func formatSentence(sentence:String) -> String
{
do {
let regex = try NSRegularExpression(pattern: "\\W+", options: .caseInsensitive)
let modifiedString = regex.stringByReplacingMatches(in: sentence, options: [], range: NSRange(location: 0,length: sentence.count), withTemplate: "")
} catch {
print(error)
}
//I tried adding it here the return modifiedString but gives me error
}
This is what the original function looks like
func formatSentence(sentence:String) -> String
{
let regex = NSRegularExpression(pattern: "\\W+", options: .caseInsensitive)//NSRegularExpression(pattern:"\\W+", options: .CaseInsensitive, error: nil)
let modifiedString = regex.stringByReplacingMatches(in: sentence, options: [], range: NSRange(location: 0,length: sentence.count), withTemplate: "")
return modifiedString
}