Swift 2b3: Proposed extension to make StringLiteralConvertible less of a pain to implement

Originator:rix.rob
Number:rdar://21783922 Date Originated:11-Jul-2015 09:58 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode-beta (7A152u)
Classification:Enhancement Reproducible:Always
 
Summary:
If somebody wants to implement StringLiteralConvertible, it may not be obvious to them why they’d want to implement UnicodeScalarLiteralConvertible. (In fact, they probably wouldn’t want to.) That much more so ExtendedGraphemeClusterLiteralConvertible, which is a hell of a symbol to confront someone with when they just want to be able to specify some Identifier instance as a string literal in their source.

Fortunately this can be resolved using protocol extensions. We can write this:

extension StringLiteralConvertible where StringLiteralType == String {
	public init(unicodeScalarLiteral: String) {
		self.init(stringLiteral: unicodeScalarLiteral)
	}

	public init(extendedGraphemeClusterLiteral: String) {
		self.init(stringLiteral: extendedGraphemeClusterLiteral)
	}
}

This works nicely, and I propose adding it to the stdlib so as to avoid the emotional drain/mental scarring of ExtendedGraphemeClusterLiteralConvertibleManagerConverterFactoryObjectControllerType.

Steps to Reproduce:
N/A

Expected Results:
N/A

Actual Results:
N/A

Regression:
N/A

Notes:
N/A

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!