[swift-evolution] Pitch: Member lookup on String should not find members of NSString

Johannes Weiß johannesweiss at apple.com
Wed Oct 25 02:36:58 CDT 2017


+1, it's currently really non-obvious where these automatic bridges are happening which keeps costing me time.

> On 24 Oct 2017, at 11:00 pm, Slava Pestov via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Hi,
> 
> Members of NSString, except those defined in Foundation, are available on values of type String. For example,
> 
> extension NSString {
>  @objc func foo() {}
> }
> 
> let s: String = “hello”
> 
> s.foo()
> 
> We don’t do this for any other bridged types, for instance NSArray methods are not imported as Array methods. It’s literally a special case in the type checker for member lookup on String.
> 
> This behavior doesn’t really much sense conceptually and it was put in as a stop-gap in Swift 1 to beef up the String API. I would like to phase it out as follows:
> 
> - Unconditional warning in Swift 4.1, with a fixit to insert an ‘as NSString’ cast
> - Error in Swift 5 with -swift-version 5
> 
> What does everyone think about this?
> 
> Slava
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list