Swift iOS take in a input and use it for function name -
func callfunctionname(parameters: string) -> returntype { var somevalue = parameters var returnvalue = somevalue() return returnvalue }
is there way take in input , use function name?
example: let input green, want call function green. if input red call function red etc...
or have huge if statement check each input call different functions
this not possible in swift. have store functions want call in your own dictionary, , use functions name.
a "huge statement" might feasible small number of functions, , perform faster, ideal approach store them in dictionary.
however, if dealing objects:
if exampleobject.respondstoselector("examplefunction") { exampleobject.performselector("examplefunction") }
this approach works classes, objective-c or swift.
Comments
Post a Comment