[swift-users] Possible swift 3 method rewrite issue with NSRequestConcreteImplementation ?
John Spurlock
john.spurlock at gmail.com
Mon Jul 18 02:11:43 CDT 2016
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160718/702fc5d1/attachment.html>
More information about the swift-users
mailing list