[swift-users] Overload by return type optionality?

Rick Mann rmann at latencyzero.com
Thu Oct 13 16:36:02 CDT 2016


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




More information about the swift-users mailing list