[swift-users] Possible swift 3 method rewrite issue with NSRequestConcreteImplementation ?
Tony Parker
anthony.parker at apple.com
Mon Jul 18 19:37:28 CDT 2016
Probably, but there could be a compiler bug or importer bug lurking here.
- Tony
> On Jul 18, 2016, at 5:29 PM, Jacob Bandes-Storch <jtbandes at gmail.com> wrote:
>
> Shouldn't that be implicit, since the function is `override`?
>
> On Mon, Jul 18, 2016 at 5:25 PM, Tony Parker via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
> Hi John,
>
> Can you try this?
>
> @objc(encodeInt:forKey:)
> override func encode(_ intv: Int, forKey key: String) {
> print("\(key) \(intv)") // never called
> }
>
> - Tony
>
> > On Jul 18, 2016, at 12:11 AM, John Spurlock via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
> >
> > 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.
> >
> > What am I missing here? Without source code for any of this, I'm at a dead end.
> >
> > Thanks,
> > - john
> >
> > ================================================
> >
> > private class FooCoder : NSCoder {
> > override var allowsKeyedCoding : Bool { return true }
> >
> > override func encode(_ objv: AnyObject?, forKey key: String) {
> > print("\(key) \(objv)") // called
> > }
> >
> > override func encode(_ intv: Int, forKey key: String) {
> > print("\(key) \(intv)") // never called
> > }
> > }
> >
> > func testCoder() {
> > Calendar.current.encode(with: FooCoder()) // crashes at runtime, result below
> > }
> >
> > Results in:
> >
> > "NSInvalidArgumentException", "*** -encodeInt:forKey: only defined for abstract class. Define -[_TtCC22Tests22TestsP33_1961FooCoder encodeInt:forKey:]!"
> > (
> > 0 CoreFoundation 0x00007fff84da34f2 __exceptionPreprocess + 178
> > 1 libobjc.A.dylib 0x00007fff883caf7e objc_exception_throw + 48
> > 2 CoreFoundation 0x00007fff84e0a4bd +[NSException raise:format:] + 205
> > 3 Foundation 0x00007fff903ccdbd NSRequestConcreteImplementation + 229
> > 4 Foundation 0x00007fff9035323b -[NSCalendar(NSCalendar) encodeWithCoder:] + 251
> > _______________________________________________
> > swift-users mailing list
> > swift-users at swift.org <mailto:swift-users at swift.org>
> > https://lists.swift.org/mailman/listinfo/swift-users <https://lists.swift.org/mailman/listinfo/swift-users>
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org <mailto:swift-users at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-users <https://lists.swift.org/mailman/listinfo/swift-users>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160718/743eeb5c/attachment.html>
More information about the swift-users
mailing list