Shadow Of Shadow Of - 1 year ago 157
Swift Question

Custom literal method with LiteralConvertible

I am reading about

protocols (lets take
for example), and I found that in swift 1.2 you can use implicit typecasting from literal to your custom
type. Following example taken from NSHipster blog:

struct SomeStruct: StringLiteralConvertible {
init(stringLiteral value: String) {}
init(extendedGraphemeClusterLiteral value: String) {}
init(unicodeScalarLiteral value: String) {}
func someFunc(){}

Somewhere in executable space:

let someStruct: SomeStruct = "

Answer Source

It wouldn't make sense, w.r.t. type safety and non-ambiguity, if the last row ("

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download