The following function is returning another function as its result which can be later assigned to a variable and called.
function jediTrainer takes 0 arguments. It returns a function that (takes in a String and an Int, and returns a String)
1 2 3 4 5 6 7 8 9 10 11 12 13 |
func jediTrainer () -> ((String, Int) -> String) { // we create a function definition that (takes in a String and an Int, and returns a String) func train(name: String, times: Int) -> (String) { return "\(name) has been trained in the Force \(times) times" } // then simply return that function return train } // variable 'train' takes on the function. Then it uses that function by using the interface let train = jediTrainer() train("Obi Wan", 3) |