Skip to content

[NSDictionary] Implement description, descriptionWithLocale, descriptionWithLocale:indent and tests #114

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 1 commit into from
Dec 16, 2015

Conversation

thii
Copy link
Contributor

@thii thii commented Dec 10, 2015

No description provided.

get {
var _description: String = "{\n"
for key in self.allKeys {
_description += " \(key) = \(objectForKey(key)!);\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if you have a dictionary of strings to dictionaries? shouldn't this cascade with indentation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phausler also what would the expected behaviour be in this situation if someone has done something like make a dictionary of dictionaries with many levels of depth? Some kind of termination at some point?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so description should probably call descriptionWithLocale:indent: which that I would not expect to iterate more than say 100 deep. most likely at that level there is probably an error in the caller's code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍- perfect, thanks for the heads up and apologies for the rookie move on my part by not looking there first 😊

@phausler phausler self-assigned this Dec 10, 2015
@thii
Copy link
Contributor Author

thii commented Dec 14, 2015

What would be the expected behavior if a negative indent level is passed?

@phausler
Copy link
Contributor

id say that would definitely be in the territory of programmer error or undefined behavior for the darwin version. So perhaps precondition if you think it warrants it; the objc version's interface is an NSUInteger for the level which gets translated to Int in swift unfortunately.

@thii
Copy link
Contributor Author

thii commented Dec 14, 2015

It that okay to change the indent level type to UInt?

@phausler
Copy link
Contributor

UInt would diverge from the API that is currently exposed in swift on Darwin platforms. Even though it would be more type safe it would diverge usage patterns. So lets keep it as Int

@thii
Copy link
Contributor Author

thii commented Dec 14, 2015

I updated it as requested. Since most classes' descriptionWithLocale: and descriptionWithLocale:indent: are unimplemented, I only added some basic tests.

@thii thii changed the title Implement NSDictionary.description [NSDictionary] Implement description, descriptionWithLocale, descriptionWithLocale:indent and tests Dec 14, 2015
@phausler
Copy link
Contributor

looks like a pretty decent start to me, will merge once I can verify tests on linux

phausler added a commit that referenced this pull request Dec 16, 2015
[NSDictionary] Implement description, descriptionWithLocale, descriptionWithLocale:indent and tests
@phausler phausler merged commit a6cc024 into swiftlang:master Dec 16, 2015
@thii thii deleted the nsdictionary-description branch December 16, 2015 15:15
atrick pushed a commit to atrick/swift-corelibs-foundation that referenced this pull request Jan 12, 2021
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.

4 participants