Here is an example of a recursive function in Swift. The function calculates the factorial of a given number:
main.swift117 chars8 linesThis function calls itself with a smaller value of n until the base case of n == 0 is reached. The base case stops the recursion and allows the function to start returning values back up the call stack.
gistlibby LogSnag