-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Description
| Previous ID | SR-13784 |
| Radar | rdar://problem/70730985 |
| Original Reporter | Rostyslav_D (JIRA User) |
| Type | Bug |
Environment
Swift 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
Xcode 12.0 GM
Additional Detail from JIRA
| Votes | 0 |
| Component/s | Foundation, Standard Library |
| Labels | Bug |
| Assignee | None |
| Priority | Medium |
md5: 39638118a3a39937e75933935b5cef3d
Issue Description:
In my project I extended a UnitAngle with a custom unit that relies on UnitConverter subclass:
extension UnitAngle {
static let cosine = UnitAngle(symbol: "cosφ", converter: CosineUnitConverter())
}
class CosineUnitConverter: UnitConverter, NSSecureCoding, Codable {
static var supportsSecureCoding: Bool { true }
required convenience init?(coder: NSCoder) {
self.init()
}
func encode(with coder: NSCoder) { }
override func baseUnitValue(fromValue value: Double) -> Double {
let rad = acos(value)
return rad / .pi * 180
}
override func value(fromBaseUnitValue baseUnitValue: Double) -> Double {
let rad = baseUnitValue * .pi / 180
return cos(rad)
}
}In that converter I added conformance to NSSecureCoding similarly as UnitConverterLinear does.
During attempt to serialize such a measurement with NSKeyedArchiver I get a runtime exception EXC_BAD_INSTRUCTION:
let archiver = NSKeyedArchiver(requiringSecureCoding: false)
let measurement = Measurement<UnitAngle>(value: 1, unit: .cosine)
try archiver.encodeEncodable(measurement, forKey: NSKeyedArchiveRootObjectKey)