Skip to content

Instantly share code, notes, and snippets.

@mateuszszklarek
Last active February 19, 2019 12:21
Show Gist options
  • Save mateuszszklarek/a9257928350a5b24e93abb871094447a to your computer and use it in GitHub Desktop.
Save mateuszszklarek/a9257928350a5b24e93abb871094447a to your computer and use it in GitHub Desktop.
struct Q: ExpressibleByStringLiteral {
typealias StringLiteralType = String
var question: String
init?(_ possibleQuestion: StringLiteralType) {
return nil
}
init(stringLiteral str: StringLiteralType) {
self.question = str
}
}
// Swift 4.2
_ = Q("ultimate question") // 'nil'
_ = "ultimate question" as Q // Q(question: 'ultimate question')
// Swift 5
_ = Q("ultimate question") // Q(question: "ultimate question")
_ = "ultimate question" as Q // Q(question: 'ultimate question')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment