<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 18, 2016, at 11:42 AM, Peter Eddy via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hello,<div class=""><br class=""></div><div class="">I'd like to understand why I'm unable to use the nil coalescing operator with functions.</div><div class=""><br class=""></div><div class="">For example, I'd like to write a function that takes an optional function as a parameter and that uses the nil coalescing operator to select a default function if the function's function parameter is nil, e.g:</div><div class=""><br class=""></div><div class=""><div class=""> func test(x: ((String) -> String)? = nil) {</div><div class=""><br class=""></div><div class=""> let qq = { (p:String) -> String in return "..." }</div><div class=""><br class=""></div><div class=""> let fn: String -> String = x ?? qq</div><div class=""><br class=""></div><div class=""> fn("test")</div><div class=""> }</div></div><div class=""><br class=""></div><div class="">When I do this the compiler complains that:</div><div class=""><br class=""></div><div class=""> Binary operator '??' cannot be applied to operands of type '((String) -> String)?' and '(String) -> String:</div><div class=""><br class=""></div><div class="">In the Swift 2.2 Language Guide (<a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/BasicOperators.html" class="">https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/BasicOperators.html</a>) it states:</div></div></div></blockquote><br class=""></div><div>This is a bug, which has already been fixed in master. The fix will go out with Swift 3.</div><div><br class=""></div><div>-Chris</div><br class=""></body></html>