<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-2022-jp">
</head>
<body dir="auto">
<div>It's because there is no character literal!</div>
<div id="AppleMailSignature">something like 'c','\xxxx' in language C.</div>
<div id="AppleMailSignature"><br>
</div>
<div id="AppleMailSignature"><br>
</div>
<div><br>
$B:_(B 2016$BG/(B7$B7n(B22$BF|!$(B00:54$B!$(BRoman Levenstein via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> $B<LF;!'(B<br>
<br>
</div>
<blockquote type="cite">
<div>
<div class="">Hi,</div>
<div class=""><br class="">
</div>
<div class="">I$B!G(Bd like to propose some improvements for String initializers and String.append methods. It is addressing <a href="https://bugs.swift.org/browse/SR-1964" class="">https://bugs.swift.org/browse/SR-1964</a> (<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: </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. </div>
<div class=""><br class="">
</div>
<div class="">An example of the ambiguity:</div>
<div class=""><br class="">
</div>
<div class="">> let x = String(repeating:"0", count: 10) </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=""> ^</div>
<div class=""><br class="">
</div>
<div class="">Swift.String:11:12: note: found this candidate</div>
<div class=""> public init(repeating repeatedValue: Character, count: Int)</div>
<div class=""> ^</div>
<div class=""><br class="">
</div>
<div class="">Swift.String:21:12: note: found this candidate</div>
<div class=""> public init(repeating repeatedValue: UnicodeScalar, count: Int)</div>
<div class=""> ^</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 </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="">* `public init(repeating repeatedValue: Character, count: Int)`</div>
<div class="">* `public init(repeating repeatedValue: UnicodeScalar, count: Int)`</div>
<div class=""><br class="">
</div>
<div class="">by the following, more powerful API:</div>
<div class="">* `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="">* `public mutating func append(_ x: UnicodeScalar)`</div>
<div class="">because there is already an existing and more powerful API:</div>
<div class="">* `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>
</div>
</blockquote>
<blockquote type="cite">
<div><span>_______________________________________________</span><br>
<span>swift-evolution mailing list</span><br>
<span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br>
<span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br>
</div>
</blockquote>
</body>
</html>