Swift does already have a great solution in such a scenario.
func handler() -> Result? {
return callback?.result()
}
Does the trick. ;)
--
Adrian Zubarev
Sent with Airmail
Am 8. Februar 2017 um 20:02:38, Maxim Veksler ([email protected]) schrieb:
For example, assume that we're dealing with a callback of some form.
let callback: CallbackProtocol? = StructExampleCallback()
You could write inside you handler function:
func handler() -> Result? {
return callback ?! callback.result() : nil
}
Which would return either nil, or the callback result. I don't think you can do
it with ?? but then again guard is a valid solution for this specific use case.
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution