Skip to content
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

[Foundation] UUID: LosslessStringConvertible #28706

Closed

Conversation

benrimmington
Copy link
Contributor

UUID already conforms to CustomStringConvertible,
but in documentation its description property
is only a "textual description of the UUID."

LosslessStringConvertible conformance will make:

  • description and uuidString equivalent;
  • "\(UUID())" interpolation more useful;
  • String(UUID()) creation possible.

@benrimmington
Copy link
Contributor Author

@parkera Please let me know if these changes can be accepted into the Foundation overlay (and also swift-corelibs-foundation).

@parkera
Copy link
Contributor

parkera commented Dec 11, 2019

Can you expand a bit on what the benefits of adopting the protocol are?

Also, I think we may not be able to do this until Swift provides an ABI-compatible way to adopt an existing protocol on an existing type.

@benrimmington
Copy link
Contributor Author

Can you expand a bit on what the benefits of adopting the protocol are?

There may be existing code that relies on "\(uuid)" interpolation:

  • either accidentally if "\(uuid.uuidString)" was intended;

  • or on purpose if someone looked at the implementation and unit test.

If you want to guarantee that description and uuidString are equivalent, updated documentation would be one option, but this isn't always reliable (for example, NSDatas description no longer matches its documentation). The new conformance would be a stronger guarantee.

Also, I think we may not be able to do this until Swift provides an ABI-compatible way to adopt an existing protocol on an existing type.

OK, I didn't realize that. I also forgot to add an @available placeholder to the new initializer. Do you want to close this PR for now?

@parkera
Copy link
Contributor

parkera commented Dec 11, 2019

We can close it, and I've filed a radar for us to track the idea internally as well (rdar://problem/57847799)

@benrimmington benrimmington deleted the uuid-description branch December 11, 2019 20:12
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.

None yet

2 participants