<div dir="ltr">Shouldn'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"><<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">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("\(key) \(intv)") // never called<br>
}<br>
<br>
</span>- Tony<br>
<div><div class="h5"><br>
> On Jul 18, 2016, at 12:11 AM, John Spurlock via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br>
><br>
> Minimal repro case below. I'm creating a custom NSCoder, but the "encodeInt:forKey" call is not dispatched properly to my overridden method when encoding an NSCalendar instance.<br>
><br>
> What am I missing here? Without source code for any of this, I'm at a dead end.<br>
><br>
> Thanks,<br>
> - john<br>
><br>
> ================================================<br>
><br>
> private class FooCoder : NSCoder {<br>
> override var allowsKeyedCoding : Bool { return true }<br>
><br>
> override func encode(_ objv: AnyObject?, forKey key: String) {<br>
> print("\(key) \(objv)") // called<br>
> }<br>
><br>
> override func encode(_ intv: Int, forKey key: String) {<br>
> print("\(key) \(intv)") // never called<br>
> }<br>
> }<br>
><br>
> func testCoder() {<br>
> Calendar.current.encode(with: FooCoder()) // crashes at runtime, result below<br>
> }<br>
><br>
> Results in:<br>
><br>
> "NSInvalidArgumentException", "*** -encodeInt:forKey: only defined for abstract class. Define -[_TtCC22Tests22TestsP33_1961FooCoder encodeInt:forKey:]!"<br>
> (<br>
> 0 CoreFoundation 0x00007fff84da34f2 __exceptionPreprocess + 178<br>
> 1 libobjc.A.dylib 0x00007fff883caf7e objc_exception_throw + 48<br>
> 2 CoreFoundation 0x00007fff84e0a4bd +[NSException raise:format:] + 205<br>
> 3 Foundation 0x00007fff903ccdbd NSRequestConcreteImplementation + 229<br>
> 4 Foundation 0x00007fff9035323b -[NSCalendar(NSCalendar) encodeWithCoder:] + 251<br>
</div></div>> _______________________________________________<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>
_______________________________________________<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>