Q: iOS Swift 4 Extension Range How can return an Int from a range of numbers in Swift?
I want to return an Int from a range of two numbers. Ultimately my goal is to assign the returned Int value to an indexPath.row of a tableview in cellforpathatindex method. I have written the extension but when I print the return value which is in the example below is k, I am only getting the min value instead of the entire range of values. 
   extension Range {
      func returnIndexValue(min: Int, max: Int) -> Int {
        var indexArray = [Int]()
        let range = (min..<max)

        for i in range {
        return i
    }
    for p in indexArray {
        return p
    }
        return max
    }
 }

   let range: Range<Int> = 1..<10

   var k = range.returnIndexValue(min: 6, max: 100)

   print(k)


A: Your function terminates at the first return it hits which is when it returns min in the first loop. 
Edit 
Your comments show you still don't get the problem with your code. A return statement exits the function. If you have a return in a loop as you do, the loop and the function are exited, the first time you execute the return. There's no way to magically go back and continue executing the loop. You're done.
Do you want a sequence of all the numbers in the range? Because a Range of Int is already a sequence. So you can create an array of all the values in the range simply by doing this:
let arrayOfInts = Array(1 ..< 4) // [ 1, 2, 3 ]

Your for ... in statement already does what you need, just replace the return with whatever it is you want to do for each value. For example:
for i in range
{
    print(i)
}

prints all the numbers from min to max - 1

A: if you want to return all the range of int values in an array then you can do it like that :
func returnIndexValue(min: Int, max: Int) -> [Int] {
    return Array(min...max)
}

And you don't need to use an extension for that.
