That's an interesting idea without having to write type signatures twice.

The different nullability of the absoluteURL is strange indeed - what if I do a 
guaranteed cast from NSURL to URL, and absoluteURL would have been nil in the 
original object?

Eiher way, I'd really like to know if URL extensions could be bridged too 
without casting in a future Swift version.

  -- Fabian


On 13 Nov 2016, at 03:45, Dennis Lysenko 
<[email protected]<mailto:[email protected]>> wrote:

Hmm... would it be possible to define a protocol like "UnifiedURLType", define 
each of the properties you need to work with inside your extension functions as 
protocol properties inside the protocol UnifiedURLType {} declaration, create 
an extension UnifiedURLType {} and include doSomething() inside the extension, 
and then create extensions on both URL and NSURL causing them to conform to 
UnifiedURLType? (extension URL: UnifiedURLType {}; extension NSURL: 
UnifiedURLType {})

You could try it, but I wouldn't hold my breath, especially if you're planning 
on using absoluteURL within your extension as something as basic as the type of 
that variable is already different between the two types.

Dennis

On Fri, Nov 11, 2016 at 3:08 AM Fabian Ehrentraud via swift-evolution 
<[email protected]<mailto:[email protected]>> wrote:
Hi list,

Since Swift 3 there exist overlay structs, e.g. NSURL gets bridged to URL.
Unfortunately now extensions on URL are not getting bridged back to ObjC:


extension URL {
        func doSomething() -> URL {
                return self.absoluteURL
        }
}

+ (NSURL *)swiftStructExtensionCaller {
        NSURL *url = [NSURL 
URLWithString:@"https://apple.github.io/swift-evolution/";];
        return [url doSomething];
}

The compiler does not see the method `doSomething`. Is this on purpose, or 
something that has yet to be improved?

I'm aware that I could write the extension on NSURL, but that would mean a lot 
of casting on the Swift side.


  -- Fabian
_______________________________________________
swift-evolution mailing list
[email protected]<mailto:[email protected]>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to