[swift-evolution] Swift 3 Ranges

David Hart david at hartbit.com
Tue Sep 6 01:15:33 CDT 2016

Hi people,

I’ve recently started migrating some Swift 2 projects to Swift 3. I came across the split of Range into Range and ClosedRange and I’ve really struggled with it. Specifically, in Swift 2, I had a struct with a Range property that was initialised in many places with either a closed or open range:

struct Day { … }
struct Day : Comparable { … }
struct Day : Strippable { … }

struct Info {
    let name: String
    let range: Range<Day>

Info(name: "Christmas Vacation", range: twentyfith...thirtyfirst)
Info(name: "Summer Vacation", range: someday..<otherday)

Now, in Swift 3, it seems like we’ve lost a type to represent any range to allow an API client the flexibility to specify it as he wishes. Is there a solution to this problem through a protocol which both ranges conform to, or are we stuck with this because of the new API?

protocol RangeType {
    associatedtype Bounds
    let lowerBound: Bound { get }
    let upperBound: Bound { get }
    // what else? not even sure if it is possible to define such a protocol

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160906/35e194d2/attachment.html>

More information about the swift-evolution mailing list