<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="">Probably, but there could be a compiler bug or importer bug lurking here.<div class=""><br class=""></div><div class="">- Tony</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 18, 2016, at 5:29 PM, Jacob Bandes-Storch <<a href="mailto:jtbandes@gmail.com" class="">jtbandes@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Shouldn't that be implicit, since the function is `override`?<div class="gmail_extra">
<br class=""><div class="gmail_quote">On Mon, Jul 18, 2016 at 5:25 PM, Tony Parker via swift-users <span dir="ltr" class=""><<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi John,<br class="">
<br class="">
Can you try this?<br class="">
<br class="">
@objc(encodeInt:forKey:)<br class="">
<span class="">override func encode(_ intv: Int, forKey key: String) {<br class="">
print("\(key) \(intv)") // never called<br class="">
}<br class="">
<br class="">
</span>- Tony<br class="">
<div class=""><div class="h5"><br class="">
> On Jul 18, 2016, at 12:11 AM, John Spurlock via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:<br class="">
><br class="">
> 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 class="">
><br class="">
> What am I missing here? Without source code for any of this, I'm at a dead end.<br class="">
><br class="">
> Thanks,<br class="">
> - john<br class="">
><br class="">
> ================================================<br class="">
><br class="">
> private class FooCoder : NSCoder {<br class="">
> override var allowsKeyedCoding : Bool { return true }<br class="">
><br class="">
> override func encode(_ objv: AnyObject?, forKey key: String) {<br class="">
> print("\(key) \(objv)") // called<br class="">
> }<br class="">
><br class="">
> override func encode(_ intv: Int, forKey key: String) {<br class="">
> print("\(key) \(intv)") // never called<br class="">
> }<br class="">
> }<br class="">
><br class="">
> func testCoder() {<br class="">
> Calendar.current.encode(with: FooCoder()) // crashes at runtime, result below<br class="">
> }<br class="">
><br class="">
> Results in:<br class="">
><br class="">
> "NSInvalidArgumentException", "*** -encodeInt:forKey: only defined for abstract class. Define -[_TtCC22Tests22TestsP33_1961FooCoder encodeInt:forKey:]!"<br class="">
> (<br class="">
> 0 CoreFoundation 0x00007fff84da34f2 __exceptionPreprocess + 178<br class="">
> 1 libobjc.A.dylib 0x00007fff883caf7e objc_exception_throw + 48<br class="">
> 2 CoreFoundation 0x00007fff84e0a4bd +[NSException raise:format:] + 205<br class="">
> 3 Foundation 0x00007fff903ccdbd NSRequestConcreteImplementation + 229<br class="">
> 4 Foundation 0x00007fff9035323b -[NSCalendar(NSCalendar) encodeWithCoder:] + 251<br class="">
</div></div>> _______________________________________________<br class="">
> swift-users mailing list<br class="">
> <a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">
> <a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class="">
<br class="">
_______________________________________________<br class="">
swift-users mailing list<br class="">
<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class="">
</blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></div></body></html>