Swift toString method accept all types.
| Originator: | konstantin.koval1 | ||
| Number: | rdar://17745215 | Date Originated: | 21/72014 |
| Status: | Duplicate | Resolved: | Closed |
| Product: | Developer Tools | Product Version: | Xcode 6 beta 3: Version 6.0 (6A254o) |
| Classification: | Suggestion | Reproducible: | Always |
func toString<T>(object: T) -> String
toString(10)
//"10"
class A {
let a = 10
}
let a = A()
toString(a)
// "V11lldb_expr_01B (has 1 child)"
If I implement Printable protocol in class A it looks better
class A : Printable{
let a = 10
var description:String {
return "A is \(a)"
}
}
let a = A()
toString(a)
// "A is 100"
My suggestion that toString should require method to implement Printable
func toString<T : Printable>(object: T) -> String
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!