Range Types in Swift
Matthew Liam Healy
271

For those case where you think you need a range, but really just need a collection of Int, for which it would be convinient to pass a range:

func takeAColleciton<T: RandomAccessCollection>(_ range: T) where T.Element == Int {

print(range)

}

takeAColleciton(0…2)

takeAColleciton(0..<4)

takeAColleciton([0, 3, 5, 9])

Like what you read? Give Vincent Bernier a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.