<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">I pasted you code into Xcode 8 beta3 playground, everything seemed fine with below code.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(187,44,162)">import</span><span style="font-variant-ligatures: no-common-ligatures;"> Cocoa</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(187,44,162)">import</span><span style="font-variant-ligatures: no-common-ligatures;"> CoreLocation</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures: no-common-ligatures;"></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(187,44,162)">class</span><span style="font-variant-ligatures: no-common-ligatures;"> ManifestItem: </span><span style="color:rgb(112,61,170)">NSObject</span><span style="font-variant-ligatures: no-common-ligatures;"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">let</span><span style="font-variant-ligatures: no-common-ligatures;"> value: </span><span style="color:rgb(112,61,170)">String</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">let</span><span style="font-variant-ligatures: no-common-ligatures;"> title: </span><span style="color:rgb(112,61,170)">String</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">let</span><span style="font-variant-ligatures: no-common-ligatures;"> subtitle: </span><span style="color:rgb(112,61,170)">String</span><span style="font-variant-ligatures: no-common-ligatures;">?</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(112,61,170)"><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(187,44,162)">dynamic</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(187,44,162)">var</span><span style="color:rgb(0,0,0)"> coordinate: </span><span style="font-variant-ligatures: no-common-ligatures;">CLLocationCoordinate2D</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures: no-common-ligatures;"> </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">init</span><span style="font-variant-ligatures: no-common-ligatures;">(value:</span><span style="color:rgb(112,61,170)">String</span><span style="font-variant-ligatures: no-common-ligatures;">, title:</span><span style="color:rgb(112,61,170)">String</span><span style="font-variant-ligatures: no-common-ligatures;">, subtitle:</span><span style="color:rgb(112,61,170)">String</span><span style="font-variant-ligatures: no-common-ligatures;">? = </span><span style="color:rgb(187,44,162)">nil</span><span style="font-variant-ligatures: no-common-ligatures;">, coordinate:</span><span style="color:rgb(112,61,170)">CLLocationCoordinate2D</span><span style="font-variant-ligatures: no-common-ligatures;">) {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">self</span><span style="font-variant-ligatures: no-common-ligatures;">.</span><span style="color:rgb(79,129,135)">value</span><span style="font-variant-ligatures: no-common-ligatures;"> = value</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">self</span><span style="font-variant-ligatures: no-common-ligatures;">.</span><span style="color:rgb(79,129,135)">title</span><span style="font-variant-ligatures: no-common-ligatures;"> = title</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">self</span><span style="font-variant-ligatures: no-common-ligatures;">.</span><span style="color:rgb(79,129,135)">subtitle</span><span style="font-variant-ligatures: no-common-ligatures;"> = subtitle</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">self</span><span style="font-variant-ligatures: no-common-ligatures;">.</span><span style="color:rgb(79,129,135)">coordinate</span><span style="font-variant-ligatures: no-common-ligatures;"> = coordinate</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;"> }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">}</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures: no-common-ligatures;"></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(187,44,162)">@objc</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">public</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">protocol</span><span style="font-variant-ligatures: no-common-ligatures;"> MKAnnotation : </span><span style="color:rgb(112,61,170)">NSObjectProtocol</span><span style="font-variant-ligatures: no-common-ligatures;"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures: no-common-ligatures;"> </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)"> </span><span style="font-variant-ligatures: no-common-ligatures;">// Center latitude and longitude of the annotation view.</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)"> </span><span style="font-variant-ligatures: no-common-ligatures;">// The implementation of this property must be KVO compliant.</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">var</span><span style="font-variant-ligatures: no-common-ligatures;"> coordinate: </span><span style="color:rgb(112,61,170)">CLLocationCoordinate2D</span><span style="font-variant-ligatures: no-common-ligatures;"> { </span><span style="color:rgb(187,44,162)">get</span><span style="font-variant-ligatures: no-common-ligatures;"> }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures: no-common-ligatures;"> </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)"> </span><span style="font-variant-ligatures: no-common-ligatures;">// Title and subtitle for use by selection UI.</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">@objc</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">optional</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">var</span><span style="font-variant-ligatures: no-common-ligatures;"> title: </span><span style="color:rgb(112,61,170)">String</span><span style="font-variant-ligatures: no-common-ligatures;">? { </span><span style="color:rgb(187,44,162)">get</span><span style="font-variant-ligatures: no-common-ligatures;"> }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">@objc</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">optional</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">var</span><span style="font-variant-ligatures: no-common-ligatures;"> subtitle: </span><span style="color:rgb(112,61,170)">String</span><span style="font-variant-ligatures: no-common-ligatures;">? { </span><span style="color:rgb(187,44,162)">get</span><span style="font-variant-ligatures: no-common-ligatures;"> }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">}</span></p></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">I didn't encounter the error you mentioned. But I had to remove public and add @objc as Xcode asked.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">Zhaoxin</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jul 24, 2016 at 12:09 PM, Rod Brown via swift-users <span dir="ltr"><<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi Swift Users,<div><br><div>I just ran across an issue where I had the following code:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">class</span><span> ManifestItem: </span><span style="color:#703daa">NSObject</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span> </span><span style="color:#bb2ca2">let</span><span> value: </span><span style="color:#703daa">String</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span> </span><span style="color:#bb2ca2">let</span><span> title: </span><span style="color:#703daa">String</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span> </span><span style="color:#bb2ca2">let</span><span> subtitle: </span><span style="color:#703daa">String</span><span>?</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span><span style="color:rgb(187,44,162)"> dynamic var</span><span> coordinate: </span><span style="color:rgb(112,61,170)">CLLocationCoordinate2D</span></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>}</span></div></div><div><br></div><div><br></div><div>As part of utilising this object, I needed it to conform to MKAnnotation, which declares:</div><div><br></div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">public</span><span> </span><span style="color:#bb2ca2">protocol</span><span> MKAnnotation : </span><span style="color:#703daa">NSObjectProtocol</span><span> {</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span> </span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:#000000"> </span><span>// Center latitude and longitude of the annotation view.</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:#000000"> </span><span>// The implementation of this property must be KVO compliant.</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span> </span><span style="color:#bb2ca2">public</span><span> </span><span style="color:#bb2ca2">var</span><span> coordinate: </span><span style="color:#703daa">CLLocationCoordinate2D</span><span> { </span><span style="color:#bb2ca2">get</span><span> }</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span> </span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:#000000"> </span><span>// Title and subtitle for use by selection UI.</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span> </span><span style="color:#bb2ca2">optional</span><span> </span><span style="color:#bb2ca2">public</span><span> </span><span style="color:#bb2ca2">var</span><span> title: </span><span style="color:#703daa">String</span><span>? { </span><span style="color:#bb2ca2">get</span><span> }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span> </span><span style="color:#bb2ca2">optional</span><span> </span><span style="color:#bb2ca2">public</span><span> </span><span style="color:#bb2ca2">var</span><span> subtitle: </span><span style="color:#703daa">String</span><span>? { </span><span style="color:#bb2ca2">get</span><span> }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>}</span></div></div><div><span><br></span></div><div><span>I added the appropriate extension to “ManifestItem” and promptly got reminded with an error that MKAnnotation requires title be an optional.</span></div><div><span><br></span></div><div><span>To do this, I converted “title” in my ManifestItem class to be an implicitly unwrapped optional. This value can never be nil, and should be treated as such throughout my code. However, the compiler still emits a warning. "</span>Type of 'title' has different optionality than expected by protocol ‘MKAnnotation' "</div><div><span><br></span></div><div><span>I’m wondering if this should be considered a bug? I am actually comforming correctly to the protocol - title is optional, though implicitly unwrapped. Should I have to make “title” optional, and every use of it optional or a force unwrap, when my code verifies that the manifest item is legitimately invalid if title property is nil?</span></div><div><span><br></span></div><div><span>I think this is valid use of the implicitly unwrapped optional. It allows you to say “this is optional for some reason, but should generally always be assumed to be non null.” This sounds remarkably similar to my use case "</span>this is optional for conformance reasons, but should generally always be assumed to be non null.”</div><div><br></div><div>Thanks for your opinions,</div><div><br></div><div>Rod</div></div></div><br>_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>