<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi,</div><div class=""><br class=""></div><div class="">I’d like to propose some improvements for String initializers and String.append methods. It is addressing&nbsp;<a href="https://bugs.swift.org/browse/SR-1964" class="">https://bugs.swift.org/browse/SR-1964</a>&nbsp;(<a href="rdar://problem/17028332" style="color: rgb(59, 115, 175); text-decoration: none; font-family: Arial, sans-serif; font-size: 14px;" class="">rdar://problem/17028332</a>).</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class=""># Replace String.init(repeating repeatedValue: Character, count: Int) and String.init(repeating repeatedValue: UnicodeScalar, count: Int) by String.init(repeating repeatedValue: String, count: Int)</div><div class=""><br class=""></div><div class="">* Proposal:</div><div class="">* Author: [Roman Levenstein](<a href="http://github.com/swiftix" class="">http://github.com/swiftix</a>)</div><div class="">* Status:&nbsp;</div><div class="">* Review manager:</div><div class=""><br class=""></div><div class="">Introduction</div><div class="">=========</div><div class=""><br class=""></div><div class="">This proposal suggest replacing String initializers taking Character or UnicodeScalar as a repeating value by a more general initializer that takes a String as a repeating value. This is done to avoid the ambiguities in the current String API, which can be only resolved by explicit casting. It is also proposed to remove one of the String.append APIs to match these changes.</div><div class=""><br class=""></div><div class="">All user-facing Swift APIs must go through Swift Evolution. While this is a relatively simple API change with an existing implementation, this formal proposal provides a paper trail as is normal and usual for this process.</div><div class=""><br class=""></div><div class="">Motivation</div><div class="">========</div><div class=""><br class=""></div><div class="">This change introduces a non-ambiguous API for constructing Strings. With the set of String initializers available today, ones often needs to explicitly cast the repeating value literal to disambiguate what initializer is meant to be used.&nbsp;</div><div class=""><br class=""></div><div class="">An example of the ambiguity:</div><div class=""><br class=""></div><div class="">&gt; let x = String(repeating:"0", count: 10)&nbsp;</div><div class="">error: repl.swift:29:9: error: ambiguous use of 'init(repeating:count:)'</div><div class="">let x = String(repeating:"0", count: 10)</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; ^</div><div class=""><br class=""></div><div class="">Swift.String:11:12: note: found this candidate</div><div class="">&nbsp; &nbsp; public init(repeating repeatedValue: Character, count: Int)</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^</div><div class=""><br class=""></div><div class="">Swift.String:21:12: note: found this candidate</div><div class="">&nbsp; &nbsp; public init(repeating repeatedValue: UnicodeScalar, count: Int)</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^</div><div class=""><br class=""></div><div class="">To disambiguate, one currently needs to write something like:</div><div class="">`let zeroes = String(repeating: "0" as Character, count: 10)` or&nbsp;</div><div class="">`let zeroes = String(repeating: "0" as UnicodeScalar, count: 10)`</div><div class=""><br class=""></div><div class="">Detailed Design</div><div class="">============</div><div class=""><br class=""></div><div class="">This update affects `String`.</div><div class=""><br class=""></div><div class="">It is proposed to replace the following ambiguous API:</div><div class="">* &nbsp;`public init(repeating repeatedValue: Character, count: Int)`</div><div class="">* &nbsp;`public init(repeating repeatedValue: UnicodeScalar, count: Int)`</div><div class=""><br class=""></div><div class="">by the following, more powerful API:</div><div class="">* &nbsp;`public init(repeating repeatedValue: String, count: Int)`</div><div class=""><br class=""></div><div class="">To match this change, it is also proposed to remove the following String.append API:</div><div class="">* &nbsp;`public mutating func append(_ x: UnicodeScalar)`</div><div class="">because there is already an existing and more powerful API:</div><div class="">* &nbsp;`public mutating func append(_ other: String)`</div><div class=""><br class=""></div><div class="">Impact on Existing Code</div><div class="">===================</div><div class=""><br class=""></div><div class="">Existing third party code using these to be removed String APIs will need migration.</div><div class="">A fixit could be provided to automate this migration.</div><div class=""><br class=""></div><div class="">Alternatives Considered</div><div class="">==================</div><div class=""><br class=""></div><div class="">Not Applicable</div><div class=""><br class=""></div></div><div class=""><br class=""></div><div class="">-Roman</div><div class=""><br class=""></div></body></html>