Skip to content

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

Merged
merged 3 commits into from
Apr 24, 2019
Merged

Parity: NSCoding: ISO8601DateFormatter #2167

merged 3 commits into from
Apr 24, 2019

Conversation

millenomi
Copy link
Contributor

  • 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

- 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
@millenomi
Copy link
Contributor Author

@swift-ci please test

@millenomi
Copy link
Contributor Author

@swift-ci please test

1 similar comment
@millenomi
Copy link
Contributor Author

@swift-ci please test


open override func encode(with aCoder: NSCoder) {
guard aCoder.allowsKeyedCoding else {
fatalError("Encoder does not allow key encoding")

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".

Copy link
Contributor Author

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

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.

Copy link
Contributor Author

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
Copy link

@jrtibbetts jrtibbetts Apr 24, 2019

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.

Copy link
Contributor Author

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.

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?

idf.timeZone = Calendar.neutral.timeZone

return idf

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.

@millenomi
Copy link
Contributor Author

@swift-ci please test and merge

1 similar comment
@millenomi
Copy link
Contributor Author

@swift-ci please test and merge

@swift-ci swift-ci merged commit 3919af1 into swiftlang:master Apr 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants