But not Xcode shows an interesting error message: “Type `Wrapper<Element>.Index` does not conform to protocol `Comparable`”. Surely, Wrapper<Element>.Index is just Int which can be inferred from the startIndex property, for example. I tried setting the Index type explicitly:
struct Wrapper<Element>: BidirectionalCollection {
typealias Index = Int
...
}
No problem! But no, count is correct. From the docs: “endIndex: The collection's "past the end" position---that is, the position one greater than the last valid subscript argument."
···
On 28 Jun 2016, at 22:45, Roy Henderson <roy@scotmail.net> wrote:
Definitely not trying to correct your code Tim - but, being a Swift-101 guy, I'm confused by endIndex as count. Should it not be count - 1?
Roy
On 28 Jun 2016, at 20:45, Tim Vermeulen via swift-users <swift-users@swift.org <mailto:swift-users@swift.org>> wrote:
But not Xcode shows an interesting error message: “Type `Wrapper<Element>.Index` does not conform to protocol `Comparable`”. Surely, Wrapper<Element>.Index is just Int which can be inferred from the startIndex property, for example. I tried setting the Index type explicitly:
struct Wrapper<Element>: BidirectionalCollection {
typealias Index = Int
...
}
Now the code finally compiles. Bug?
_______________________________________________
swift-users mailing list
swift-users@swift.org <mailto:swift-users@swift.org> https://lists.swift.org/mailman/listinfo/swift-users