-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Parity: NSCoding: ISO8601DateFormatter #2167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parity: NSCoding: ISO8601DateFormatter #2167
Conversation
- Implement NSCoding for this type. - Add centralized fixture methods to run roundtrip and load-fixture-then-match tests. Fixes https://bugs.swift.org/browse/SR-10356
@swift-ci please test |
@swift-ci please test |
1 similar comment
@swift-ci please test |
|
||
open override func encode(with aCoder: NSCoder) { | ||
guard aCoder.allowsKeyedCoding else { | ||
fatalError("Encoder does not allow key encoding") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wording of this suggests that the formatter can't be formatted by key encoders. It may be clearer to borrow the language from init()
's guard
, such as "ISO8601DateFormatter can be encoded only by keyed archivers"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll rewrite this. (It matches the Darwin exception message, but we have freedom here.)
timeZone = nil | ||
} | ||
|
||
self.formatOptions = options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would combine this with the options
declaration, i.e.
self.formatOptions = Options(rawValue: UInt(aDecoder.decodeInteger(forKey: "NS.formatOptions")))
Or at least put this line right after the let options =
one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
|
||
if aDecoder.containsValue(forKey: "NS.timeZone") { | ||
if let tz = aDecoder.decodeObject(of: NSTimeZone.self, forKey: "NS.timeZone") { | ||
timeZone = tz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be clearer to keep all the time zone-related statements together. I would just make it
if let tz = aDecoder.decodeObject(of: NSTimeZone.self,
forKey: "NS.timeZone")?._swiftObject {
self.timeZone = tz
}
Then you can do away with lines 88 (let timeZone: NSTimeZone?
), 97-99, and 102-105 altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's too many things to parse in a single line, I feel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. But can they be grouped together a little more?
TestFoundation/FixtureValues.swift
Outdated
idf.timeZone = Calendar.neutral.timeZone | ||
|
||
return idf | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other functions don't have blank lines after the opening and before the closing braces.
@swift-ci please test and merge |
1 similar comment
@swift-ci please test and merge |
Implement NSCoding for this type.
Add centralized fixture methods to run roundtrip and load-fixture-then-match tests.
Fixes https://bugs.swift.org/browse/SR-10356