0
// Substring
func substring(_ start: Int, end: Int) -> String {
    return self.substring(with: Range(self.characters.index(self.startIndex, offsetBy: start) ..< self.characters.index(self.startIndex, offsetBy: end)))
}

Getting the below error in that return statement after updating Xcode to 10.0. Let me know how can I show the return statement according to latest swift version.

Cannot invoke initializer for type 'Range<_>' with an argument list of type '(Range)'

Sagar Chauhan
  • 5,715
  • 2
  • 22
  • 56
  • Please tag your question with the programming language you're using – Mureinik Nov 03 '18 at 09:36
  • Possible duplicate of [Cannot invoke initializer for type 'Range' with an argument list of type '(Range)'](https://stackoverflow.com/questions/50714543/cannot-invoke-initializer-for-type-rangestring-index-with-an-argument-list-o). – Martin R Nov 03 '18 at 09:43
  • 2
    Possible duplicate of [Cannot invoke initializer for type 'Range' with an argument list of type '(Range)'](https://stackoverflow.com/questions/50714543/cannot-invoke-initializer-for-type-rangestring-index-with-an-argument-list-o) – Rakesha Shastri Nov 03 '18 at 11:05

1 Answers1

0

With Xcode 10 you can choose between Swift 3, Swift 4 and Swift 4.2 versions. I assume that you mean Swift 4.2 when you are talking about the latest Swift version. Keep in your mind that substring(with:) function has deprecated since Swift 4, so you could use string slicing:

extension String {
    func substring(_ start: Int, end: Int) -> String {
        let startIndex = self.index(self.startIndex, offsetBy: start)
        let endIndex = self.index(self.startIndex, offsetBy: end)
        return String(self[startIndex...endIndex])
    }
}
AlexSmet
  • 2,141
  • 1
  • 13
  • 18