Nested function is available in swift isn't?

0 votes
52 views
asked Jan 12, 2015 in Swift by kalpana (3,995 points)
Hi All

   Nested function is available in swift isn't?

1 Answer

0 votes
answered Jan 12, 2015 by jonathan (3,105 points)

Hi

  A function can take another function as one of its arguments.

        

        func hasAnyMatches(list: [Int], condition: Int -> Bool) -> Bool {

            for item in list {

                if condition(item) {

                    return true

                }

            }

            return false

        }

        func lessThanTen(number: Int) -> Bool {

            return number < 10

        }

        var numbers = [20, 19, 7, 12]

        hasAnyMatches(numbers, lessThanTen)

...