How to use tuple in swift language?

0 votes
62 views
asked Mar 4, 2015 in Swift by codeg (2,600 points)
Hi All

  How to use tuple in swift language?

1 Answer

0 votes
answered Mar 4, 2015 by admin (8,115 points)

Hi Codeg

 func minMax(array: [Int]) -> (min: Int, max: Int) {

            var currentMin = array[0]

            var currentMax = array[0]

            for value in array[1..<array.count] {

                if value < currentMin {

                    currentMin = value

                } else if value > currentMax {

                    currentMax = value

                }

            }

            return (currentMin, currentMax)

        }

Function call

let bounds = minMax([8, -6, 2, 109, 3, 71])

        println("min is \(bounds.min) and max is \(bounds.max)")

...