<div dir="ltr">Shouldn&#39;t that be implicit, since the function is `override`?<div class="gmail_extra">
<br><div class="gmail_quote">On Mon, Jul 18, 2016 at 5:25 PM, Tony Parker via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi John,<br>
<br>
Can you try this?<br>
<br>
@objc(encodeInt:forKey:)<br>
<span class="">override func encode(_ intv: Int, forKey key: String) {<br>
            print(&quot;\(key) \(intv)&quot;) // never called<br>
}<br>
<br>
</span>- Tony<br>
<div><div class="h5"><br>
&gt; On Jul 18, 2016, at 12:11 AM, John Spurlock via swift-users &lt;<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt; Minimal repro case below.  I&#39;m creating a custom NSCoder, but the &quot;encodeInt:forKey&quot; call is not dispatched properly to my overridden method when encoding an NSCalendar instance.<br>
&gt;<br>
&gt; What am I missing here?  Without source code for any of this, I&#39;m at a dead end.<br>
&gt;<br>
&gt; Thanks,<br>
&gt; - john<br>
&gt;<br>
&gt; ================================================<br>
&gt;<br>
&gt;     private class FooCoder : NSCoder {<br>
&gt;         override var allowsKeyedCoding : Bool { return true }<br>
&gt;<br>
&gt;         override func encode(_ objv: AnyObject?, forKey key: String) {<br>
&gt;             print(&quot;\(key) \(objv)&quot;) // called<br>
&gt;         }<br>
&gt;<br>
&gt;         override func encode(_ intv: Int, forKey key: String) {<br>
&gt;             print(&quot;\(key) \(intv)&quot;) // never called<br>
&gt;         }<br>
&gt;     }<br>
&gt;<br>
&gt;     func testCoder() {<br>
&gt;         Calendar.current.encode(with: FooCoder())  // crashes at runtime, result below<br>
&gt;     }<br>
&gt;<br>
&gt; Results in:<br>
&gt;<br>
&gt; &quot;NSInvalidArgumentException&quot;, &quot;*** -encodeInt:forKey: only defined for abstract class.  Define -[_TtCC22Tests22TestsP33_1961FooCoder encodeInt:forKey:]!&quot;<br>
&gt; (<br>
&gt;       0   CoreFoundation                      0x00007fff84da34f2 __exceptionPreprocess + 178<br>
&gt;       1   libobjc.A.dylib                     0x00007fff883caf7e objc_exception_throw + 48<br>
&gt;       2   CoreFoundation                      0x00007fff84e0a4bd +[NSException raise:format:] + 205<br>
&gt;       3   Foundation                          0x00007fff903ccdbd NSRequestConcreteImplementation + 229<br>
&gt;       4   Foundation                          0x00007fff9035323b -[NSCalendar(NSCalendar) encodeWithCoder:] + 251<br>
</div></div>&gt; _______________________________________________<br>
&gt; swift-users mailing list<br>
&gt; <a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
&gt; <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>
_______________________________________________<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>
</blockquote></div><br></div></div>