Swift: how to return class type from function

You can return any type you want.

func getTypeOfInt()  -> Int.Type  { return Int.self  }
func getTypeOfBool() -> Bool.Type { return Bool.self }

If the type is not determined from arguments or if the return is constant, there is no need to introduce a generic T type.

Leave a Comment