I have a generic class which contains a variable of generic data type. I need to convert this variable to String.
Example Code -
class test<T> {
var value:T!
var name: String!
init(text: String, val: T)
{
name = text
value = val
}
func toString() -> String {
let temp = value as! String
//let temp = String(value)
return name + ": " + temp
}
}
I tried down-casting it by doing let temp = value as! String but it leads to crash during run time
Doing let temp = String(value) throws Cannot invoke initializer for type 'String' with an argument list of type '(T?)' build error