[swift-evolution] !? operator for ternary conditional unwrapping
Adrian Zubarev
adrian.zubarev at devandartist.com
Wed Feb 8 13:05:29 CST 2017
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 (maxim at vekslers.org) 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170208/d89d5d19/attachment.html>
More information about the swift-evolution
mailing list