> On Mar 27, 2017, at 1:48 PM, Adrian Zubarev via swift-evolution 
> <swift-evolution@swift.org> wrote:
> 
> Assuming we’ll get that functionality, both var and let should satisfy the 
> protocol requirements right?
> 
In theory, there’s no reason not to allow that.

> If it is valid, could we potentially get optional functions in pure Swift as 
> well?
> 
> 
I mean, you can already do this:

protocol P {
  var optionalRequirement: ((Int) -> ())? { get }
}

extension P {
  // “default implementation"
  var optionalRequirement: ((Int) -> ())? { return nil }
}

struct A : P {}

struct B : P {
  let optionalRequirement: ((Int) -> ())? = { (x: Int) in print(x) }
}

But it’s kind of tacky.

If you think about it, “optional requirement” is an oxymoron. What’s your 
use-case?

Slava
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to