Skip to content

Instantly share code, notes, and snippets.

@russbishop
Created September 9, 2016 18:31
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save russbishop/cc0e80166e52ee40e57bb39165b08f37 to your computer and use it in GitHub Desktop.
Save russbishop/cc0e80166e52ee40e57bb39165b08f37 to your computer and use it in GitHub Desktop.
Make ExpressibleByStringLiteral tolerable
// If you want types initializable from String literals
// but don't want to implement three separate initializers.
extension ExpressibleByUnicodeScalarLiteral where Self: ExpressibleByStringLiteral, Self.StringLiteralType == String {
public init(unicodeScalarLiteral value: String) {
self.init(stringLiteral: value)
}
}
extension ExpressibleByExtendedGraphemeClusterLiteral where Self: ExpressibleByStringLiteral, Self.StringLiteralType == String {
public init(extendedGraphemeClusterLiteral value: String) {
self.init(stringLiteral: value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment