[swift-evolution] [Pitch] String prefix operator

Charlie Monroe charlie at charliemonroe.net
Fri Jun 17 00:46:51 CDT 2016


Motivational example:

var urlString = self.urlString
if urlString.hasPrefix("//") {
	urlString = "http:" + urlString // urlString needs to be typed twice
}

While there is currently an easy way to append string using +=, there is no shortcut for prefixing a string. What I propose is adding a =+ operator for prefixing the string:

urlString =+ "http:"

Would anyone else find it useful?


More information about the swift-evolution mailing list