[swift-users] Overload by return type optionality?

Luis Ferro lferro9000 at gmail.com
Fri Oct 14 14:42:11 CDT 2016


It may also work if you create a "generic" extension that can only be 
applied to strings.

Then i'm guessing that you will not need to specify the type on the use.

LF



On 13/10/2016 22:44, Nevin Brackett-Rozinsky via swift-users wrote:
> It works if you specify the types of the variables:
>
> let a: String = …
> if let b: String = …
>
> Nevin
>
>
> On Thu, Oct 13, 2016 at 5:36 PM, Rick Mann via swift-users 
> <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
>
>     It seems I can write this:
>
>     extension String
>     {
>       public func deleting(prefix inPrefix: String) -> String
>       public func deleting(prefix inPrefix: String) -> String?
>     }
>
>     But I was hoping it would do the right thing:
>
>     let a = s.deleting(prefix: "foo")
>     if let b = s.deleting(prefix: "foo") { }
>
>     But it finds these ambiguous, and I'm not sure how to specify
>     which I want.
>
>     I'm having trouble googling for an answer on this. Some answers
>     around generics, but that doesn't apply in this case.
>
>     --
>     Rick Mann
>     rmann at latencyzero.com <mailto:rmann at latencyzero.com>
>
>
>     _______________________________________________
>     swift-users mailing list
>     swift-users at swift.org <mailto:swift-users at swift.org>
>     https://lists.swift.org/mailman/listinfo/swift-users
>     <https://lists.swift.org/mailman/listinfo/swift-users>
>
>
>
>
> _______________________________________________
> 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/20161014/7e11721c/attachment.html>


More information about the swift-users mailing list