I have this class
class Foo{
public class func barFunction(){}
public class func barFunction2(){}
public class func barFunction3(){}
}
At the moment i have a switch function to determine which bar method to call
switch bar{
case "bar": Foo.barFunction(param:Double)
case "bar2": Foo.barFunction2(param:Double)
case "bar3": Foo.barFunction3(param:Double)
default: return
}
This whole thing would be a lot easier if i could compose the name of the bar function by concatenating strings and just call the method by string name.
I've read that in Swift, closures are the way to go, but i can't really figure out how closures would make it easier than the switch operation.
EDIT: Just to be clear, i want to call a class func with parameters by name (string)
EDIT(2): I need it to work like this because i have db objects of certain types, and either special classes or a special methods to draw those objects on the screen. When i get an object from the database i get its type as a string, which currently i'm feeding in the switch statement to determine how it will be drawn. Also, each object has different colours and i have this code right here to determine the color:
public class func getColors(iconType:String)->UIColor?{
switch iconType{
case "type1": return Assets.type1Color
case "type2": return Assets.type2Color
case "type3": return Assets.type3Color
case "type4": return Assets.type4Color
...
default: return nil
}
}
I feel it's redundant and that it could be simplified a lot by using strings to get variables or functions. If there is any other way to do this, please tell me.