Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return a Range of Int in Swift?

Tags:

swift

How can I return a Range of Int from a function in Swift? I've searched the Swift 2.1 docs, the web, SO, and tried:

func myfunc() -> Range { // }
func myfunc() -> ( Int ... Int ) { // }
func myfunc() -> Range< Int >  { // }

... and many others ...

Sorry for being bone-headed here, and thanks in advance!

like image 752
Dribbler Avatar asked Oct 24 '25 05:10

Dribbler


1 Answers

Your third one is correct. This compiles and works, for example:

func oneTo10() -> Range<Int> { 
   return 1...10 
}  
like image 177
Catfish_Man Avatar answered Oct 26 '25 21:10

Catfish_Man