I know it is possible to pass class type to a function in swift:
func setGeneric(type: T.Type){ } setGeneric(Int.self)
But how we can
Yes, this is possible. The problem here is that you say your function returns a generic T.type, but you always return Int.type. Since T is not always an Int, the compiler raises an error.
T.type
Int.type