[swift-evolution] Trial balloon: Ensure that String always contains valid Unicode

Kevin Ballard kevin at sb.org
Mon Jan 4 17:11:34 CST 2016


On Mon, Jan 4, 2016, at 03:08 PM, Paul Cantrell wrote:
>>> But doing lazy checking of strings would end up having to check
>>> *every* string that comes from ObjC
>
> I don’t think that’s necessarily true. There’s a limited set of places
> where invalid Unicode can creep into an NSString, and so the lazy
> check could probably bypass quite a few common cases — an ASCII string
> for example. Without digging into it, I suspect any NSString created
> from UTF-8 data can be safely bridged, since unpaired surrogate chars
> can’t make it through UTF-8.

Every single method you implement that takes a `String` property and is
either exposed to Obj-C or is overriding an Obj-C declaration will have
to check the String parameter every single time the function is called.

Every time you call an Obj-C method that returns a String, you'll have
to check that String result.

Basically, any time a String object is backed by an NSString, which is
going to be very common in most apps, that backing NSString will have to
be checked.

-Kevin Ballard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160104/70237bc7/attachment.html>


More information about the swift-evolution mailing list