<div dir="ltr">Hi Tony - when I add that attribute, I get an error at compile-time:<div><div>Objective-C method has a different selector from the method it overrides ('encodeInt:forKey:' vs. 'encodeInteger:forKey:')<br></div><div><br></div><div>If I update to encodeInteger:forKey as the fix describes, it compiles, but I'm getting the same original problem at runtime. i.e. "<span style="font-size:12.8px">encodeInt:forKey: only defined for abstract class"</span></div></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Any other ideas? See the same thing over there? You should be able to paste that into a new swift 3 test.</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 18, 2016 at 8:25 PM, Tony Parker <span dir="ltr"><<a href="mailto:anthony.parker@apple.com" target="_blank">anthony.parker@apple.com</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>
</blockquote></div><br></div>