0

There is a function

func find(... rangeString1: Range<String.Index>, ...) ...

and this function has in swift2

while i >= minimalIdentity{

var first = rangeString1.startIndex
var last = first.advancedBy(i, limit: rangeString1.endIndex)
...

Question is how should look the

var last  

in swift3

var first = rangeString1.lowerBound
var last = 
VYT
  • 1,071
  • 19
  • 35
  • Related: http://stackoverflow.com/questions/38070273/cant-create-a-range-in-swift-3. – Martin R Jul 08 '16 at 04:48
  • @Martin R Thanks. Is there swift 2 analog of last for range in swift3. I see only upperBound, but it is analog of endIndex in swift2 ? – VYT Jul 08 '16 at 08:09
  • Yes, as I mentioned in that answer, start/endIndex have been renamed to lower/upperBound. – Martin R Jul 08 '16 at 08:10
  • @Martin R Sorry, I mean - let last = range!.last which gives index lower on 1 unit than - let end = range!.endIndex. – VYT Jul 08 '16 at 08:14
  • Swift 3 has `Range` and `CountableRange`. The latter is a collection and has a `last` property. – Martin R Jul 08 '16 at 09:18
  • @Martin R If I am trying initialise range as CountableRange (instead of Range in swift2) compiler is complaining that index is not confirm to protocol Strideable – VYT Jul 08 '16 at 09:50
  • Yes, it doesn't work with a string index. – Martin R Jul 08 '16 at 09:52
  • @Martin R So, I have problem not only with .last for range for string (I can use indirect way with offsetBy, aka advanceBy to get the last value). But, I also cannot get count from range, and I don't have idea how to get it. Do you have an idea how to get count from range? – VYT Jul 08 '16 at 10:04
  • Here is another example for Swift 3: http://stackoverflow.com/a/38228514/1187415. In Swift 3 you always need the original collection to perform calculations with its indices. – Martin R Jul 08 '16 at 13:37

2 Answers2

1

Whatever string those indices belong to is responsible for this in Swift 3:

let first = rangeString1.lowerBound
let last = myString.index(first, offsetBy: i, limit: rangeString1.upperBound)
Tim Vermeulen
  • 12,352
  • 9
  • 44
  • 63
0

Just use endIndex:

var last = rangeString1.endIndex
Alexander
  • 59,041
  • 12
  • 98
  • 151
  • I cannot, I need advanceBy for iteration in while loop – VYT Jul 07 '16 at 21:39
  • Ah okay, well in that case I see someone already mentioned [`index(_:offsetBy:limit:)`](https://developer.apple.com/reference/foundation/indexpath/1780097-index) – Alexander Jul 08 '16 at 14:27