[swift-users] Was the String contains(_:) method changed in Swift 4?

Geordie Jay geojay at gmail.com
Wed Nov 8 04:23:57 CST 2017


Quinn "The Eskimo!" via swift-users <swift-users at swift.org> schrieb am Mi.
8. Nov. 2017 um 09:56:

>
> On 8 Nov 2017, at 08:47, Martin R via swift-users <swift-users at swift.org>
> wrote:
>
> > but apparently only if Foundation is imported.
>
> Which isn’t a huge surprise when you consider how tricky string
> containment is.


As someone who has used Swift professionally since it first came out, this
subtle API change after import actually is a surprise to me.

Would you be able to clarify where the line is between “tricky” and “not
tricky” and if possible the reasoning behind making this distinction?
Because as an outsider this seems to me like an unfortunate remnant of ObjC
rather than an obvious and forward-thinking API decision.


>
> import Foundation
>
> // U+00DF LATIN SMALL LETTER SHARP S
>
> let s = "Friedrichstra\u{df}e"
> let ss = "strasse"
> if s.contains(s) {
>     print("It's a street!")
> }


In Swiss German “Straße” and “Strasse” are equivalent (or rather, the first
one doesn’t officially exist). In High/“Standard” German they’re not /
would be pronounced differently etc. Some Germans call the “sharp s” an
“sz” instead. So the difficulty of this distinction is not restricted to
Unicode :)

Cheers,
Geordie


>
> Share and Enjoy
> --
> Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
>
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20171108/21d506c3/attachment.html>


More information about the swift-users mailing list