<div dir="ltr"><p>Wait, it looks like <code>String(byRepeatingString: aString, count: 3)</code> only works on characters and was removed, replace it with <code>aString + aString + aString</code>.</p>
<br><br><div class="gmail_quote"><div dir="ltr">On Fri, Jun 10, 2016 at 7:38 PM Saagar Jha <<a href="mailto:saagarjha28@gmail.com">saagarjha28@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><p>Yes, that’s what I meant. Basically, I see stuff like this:</p>
<pre><code>func tripleForceUnwrapping(aString: String!) -> String {
return String(byRepeatingString: aString, count: 3)
}
</code></pre><p>and later users get a crash with this:</p>
<pre><code>let possiblyNilString = someFunctionThatRetunsAnOptional()
tripleForceUnwrapping(possiblyNilString)
</code></pre><p>even though it compiles fine.</p>
<pre><code>func tripleWithoutUnwrapping(aString: String?) -> String {
return String(byRepeatingString: aString, count: 3)
}
let possiblyNilString = someFunctionThatRetunsAnOptional()
tripleWithoutUnwrapping(possiblyNilString)
</code></pre><p>meanwhile, doesn’t compile and forces the user to think “huh, it’s not compiling because there’s an Optional” and hopefully add a check</p></div><div dir="ltr">
<br><br><div class="gmail_quote"><div dir="ltr">On Fri, Jun 10, 2016 at 7:18 PM Paul Cantrell via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
> On Jun 10, 2016, at 7:43 PM, Dave Abrahams via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>
><br>
> on Thu Jun 09 2016, Saagar Jha <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>
><br>
>> Yes, that’s exactly my point. Force unwrapping optionals adds<br>
>> confusion for new users; all too often I see newcomers ending up with<br>
>> the assumption that the force unwrapping takes care of the check for<br>
>> them.<br>
><br>
> ...but, it *does*.<br>
<br>
I took Saagar to mean “the assumption that force unwrapping takes care of doing the right thing for them so they don’t ever have to think about nil at all.” Which is indeed quite common in beginner Swift code.<br>
<br>
Sadly, there is no compile-time check for mindfulness.<br>
<br>
Cheers, P<br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr">-Saagar Jha</div></div></blockquote></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr">-Saagar Jha</div></div>