Use CustomStringConvertible
, not StringLiteralConvertible
:
func myFunc<T: CustomStringConvertible>(param: T? = nil) -> String {
return "\(param)"
}
myFunc("Grimxn")
myFunc(12)
myFunc(true)
myFunc(-1.234)
Optionals
, T?
, nil
. ( - nil
T
), Optional
.
func myFunc<T: CustomStringConvertible>(param: T) -> String {
return "\(param)"
}
myFunc("Grimxn")
myFunc(12)
myFunc(true)
myFunc(-1.234)
myFunc(NSDate())