Change in String.CharacterView.Index?


(Joe Bell) #1

Howdy,

I've been building the latest Swift 3.0 and noticed that between Apr 25 and
today that String.CharacterView.Index.advance(by:) is no longer available.

This runs with an Apr 25 build (Swift 255544591c to be exact)
let string:String = "Hello, world!"
print(string.startIndex)
print(string.startIndex.advanced(by:1))

It fails with a build today (May 8, Swift 26fcf1ab4a):
test.swift:3:14: error: value of type 'Index' (aka
'String.CharacterView.Index') has no member 'advanced'
print(string.startIndex.advanced(by:1))
      ~~~~~~~^~~~~~~~~~ ~~~~~~~~

I don't know who runs swiftdoc.org but it is handy, and shows advanced(by:)
a valid method:
http://swiftdoc.org/v3.0/type/String.CharacterView.Index/

Not sure what I'm missing here!

Thanks,
Joe

···

--
Joseph Bell
http://dev.iachieved.it/iachievedit/
@iachievedit


(Dennis Weissmann) #2

Hey Joe,

The collection index model changed:

https://github.com/apple/swift-evolution/blob/master/proposals/0065-collections-move-indices.md

You now need to ask the collection for the next index:

let a = “Hello, World"
let secondIndex = a.characters.index(after: a.characters.startIndex)
print(a.characters[secondIndex]) // prints "e"

- Dennis

···

On May 8, 2016, at 7:58 PM, Joseph Bell via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

Howdy,

I've been building the latest Swift 3.0 and noticed that between Apr 25 and today that String.CharacterView.Index.advance(by:) is no longer available.

This runs with an Apr 25 build (Swift 255544591c to be exact)
let string:String = "Hello, world!"
print(string.startIndex)
print(string.startIndex.advanced(by:1))

It fails with a build today (May 8, Swift 26fcf1ab4a):
test.swift:3:14: error: value of type 'Index' (aka 'String.CharacterView.Index') has no member 'advanced'
print(string.startIndex.advanced(by:1))
      ~~~~~~~^~~~~~~~~~ ~~~~~~~~

I don't know who runs swiftdoc.org <http://swiftdoc.org/> but it is handy, and shows advanced(by:) a valid method:
http://swiftdoc.org/v3.0/type/String.CharacterView.Index/

Not sure what I'm missing here!

Thanks,
Joe

--
Joseph Bell
http://dev.iachieved.it/iachievedit/
@iachievedit
_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev