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

Geordie Jay geojay at gmail.com
Wed Nov 8 14:55:16 CST 2017

Jens Alfke <jens at mooseyard.com> schrieb am Mi. 8. Nov. 2017 um 16:54:

> On Nov 8, 2017, at 2:24 AM, Geordie Jay via swift-users <
> swift-users at swift.org> wrote:
> 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.
> The “only available after importing Foundation” thing has been around
> since 1.0 — it’s an artifact of the bridging of String and NSString*. After
> importing Foundation, the methods of NSString are implicitly available as
> an extension of String. I would think that by now the Swift standard
> library would have added those methods, but I guess not all of them…

Hi, and thanks for your response.

I’m aware of the legacy. What I meant was I’m surprised that
String.contains(anotherString) returns two different things depending
whether or not Foundation is imported.

And I was looking for some clarification re: “tricky” vs not. I gather
NSString didn’t even exist in ObjC outside of Foundation. What I was
getting at was whether it makes sense to stick with the status quo on this


> —Jens
> * And IIRC it also manifests with Array, Dictionary, and other bridged
> classes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20171108/9c92ee67/attachment.html>

More information about the swift-users mailing list