[swift-evolution] Swift Extensions on Overlay Structs

Dennis Lysenko dennis.s.lysenko at gmail.com
Sat Nov 12 20:45:31 CST 2016

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.


On Fri, Nov 11, 2016 at 3:08 AM Fabian Ehrentraud via swift-evolution <
swift-evolution at swift.org> 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
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161113/6ee0cf58/attachment.html>

More information about the swift-evolution mailing list