<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><div style="direction: inherit;">Thanks Brent,</div><div style="direction: inherit;"><br></div><div style="direction: inherit;">Yes, I hope this is something that can get cleared up eventually. As you say, hopefully when ImplicitlyUnwrappedOptional goes away we can clear this up.</div><div style="direction: inherit;"><br></div><div style="direction: inherit;">At least in the case you showed, the optionality is completely different. X will hand you back an object, rather than an Optional (enum) of that object. I understand why, semantically, they are different, and why the compiler may be unable/unwilling to vary the type on return.</div><div style="direction: inherit;"><br></div><div style="direction: inherit;">In the case of an implicitly unwrapped optional, though, they should theoretically be the same type - Optional&lt;String&gt; - with only the unwrapping behaviour differing. I expect this is part of the reason Implicitly unwrapped optional is dying out as a separate type.</div><div style="direction: inherit;"><br></div><div style="direction: inherit;">As Xin Zhang points out, this is only a warning, not an error, so I'm gonna accept it. It works correctly, at least.</div><div style="direction: inherit;"><br></div><div style="direction: inherit;">- Rod</div></div><div><br>On 25 Jul. 2016, at 2:05 am, Brent Royal-Gordon &lt;<a href="mailto:brent@architechies.com">brent@architechies.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><blockquote type="cite"><span>On Jul 23, 2016, at 9:09 PM, Rod Brown via swift-users &lt;<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; wrote:</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>However, the compiler still emits a warning. "Type of 'title' has different optionality than expected by protocol â€˜MKAnnotation' "</span><br></blockquote><span></span><br><span>Yes, I've encountered this error before. Example:</span><br><span></span><br><span> &nbsp;1&gt; import Foundation</span><br><span> &nbsp;2&gt; @objc protocol P { var x: String? { get } }</span><br><span> &nbsp;3&gt; class X: NSObject, P { let x = "" }</span><br><span>error: repl.swift:3:28: error: type of 'x' has different optionality than required by protocol 'P'</span><br><span>class X: NSObject, P { let x = "" }</span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^</span><br><span></span><br><span>Swift doesn't appear to allow covariance and contravariance when satisfying protocol requirements, or at least forbids it in optionals. It's a shame, because at least in a theoretical sense it's perfectly consistent.</span><br><span></span><br><span>Unfortunately, you've pretty much just got to do what the compiler tells you in this case. I expect that you'll at least be able to use `!` instead of `?` once ImplicitlyUnwrappedOptional is fully removed, but I don't believe we've gotten there yet.</span><br><span></span><br><span>-- </span><br><span>Brent Royal-Gordon</span><br><span>Architechies</span><br><span></span><br></div></blockquote></body></html>