Skip to content

Instantly share code, notes, and snippets.

@wildthink
Forked from russbishop/StringLiteral.swift
Created December 30, 2016 19:23
Show Gist options
  • Save wildthink/1c1e22f7f5b0b7bd68c7bfaa5101b3bf to your computer and use it in GitHub Desktop.
Save wildthink/1c1e22f7f5b0b7bd68c7bfaa5101b3bf 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