vendredi 17 avril 2020

How to take a function of any number of parameters of any type as a parameter in swift and execute it?

This is what I would like to get:

A single function that can, accept any function with any number of parameters of any type and any return type and, execute them inside, in Swift. Is it possible?

For example:

func add(number1: Int, animal: AnimalStruct) {

}

func add1(string: String) {

}

func add2() {

}

func singleAcceptFunction(function) {
 //access function's parameters
}

singleAcceptFunction(add)
singleAcceptFunction(add1)
singleAcceptFunction(add2)




Aucun commentaire:

Enregistrer un commentaire