0

I'm getting this warning for the return substring line. What is the better alternative?

///Returns an empty string when there is no path.
internal var path: String {
    if let match = range(of: "(?<=')[^']+", options: .regularExpression) {
        return substring(with: match)
    }
    return ""
}
ScottyBlades
  • 12,189
  • 5
  • 77
  • 85
  • @vadian, no it does not really, `substring(with:)` is a different method from `substring(of:)`. I wish you had commented and we could have talked about this. – ScottyBlades Mar 19 '20 at 16:53
  • It does. Please read [this answer](https://stackoverflow.com/questions/45562662/how-can-i-use-string-slicing-subscripts-in-swift-4/46617119#46617119) in the duplicate. It covers `substring(from:`, `substring(to:` and `substring(with:` – vadian Mar 19 '20 at 16:57
  • Okay. Thank you. – ScottyBlades Mar 19 '20 at 16:58

0 Answers0