swift-foundation icon indicating copy to clipboard operation
swift-foundation copied to clipboard

Support lower case UUID serialization

Open Westacular opened this issue 2 years ago • 2 comments

The UUID and NSUUID types have long been slightly out of compliance with RFC 4122, which specifies that the string representation of UUIDs should be in lower case. (I believe NSUUID has always used upper case in part because it predates that RFC?)

The use of upper case creates problems when interacting with external APIs that generate and send UUID values in their responses (in lowercase, as per the RFC) but expect exact string matches for these values in subsequent requests: a round-trip through a Swift using UUID will result in the value being transformed into an upper case spelling.

In my own projects, I've taken to using a LowercaseUUID type which wraps a UUID and overrides uuidString, description, and encode(to:) to apply a .lowercased() transformation in each case. However, it would be preferable if there was a way to specify this behaviour directly within Foundation, and it seems to me that this project presents an opportunity add this or alter the default.

Westacular avatar Apr 29 '23 20:04 Westacular

For clarification -- the issue is mostly about how UUID encodes itself, and not getting a lowercased string at runtime (via uuidString)?

parkera avatar May 09 '23 21:05 parkera

Yes, that's correct

Westacular avatar May 09 '23 22:05 Westacular