This is a way to erroneously obtain a huge number of identifiers with the same timestamp. Therefore, it is not supported by RFC 9562, and a more safe alternative - timestamp offset - is proposed.
I would recommend thoroughly studying RFC 9562 before making "let's do it just in case" suggestions.
Other commenters have already expressed preference for v7 over timeOrdered, but I just wanted to add that v7 is not just clearer and more ergonomic: it also avoids introducing ambiguity if we ever want to support a new version of UUID that’s also time-ordered.
Question that (only just) occurred to me, but alluded to I think by some other commenters, in the realm of modern usage:
As Wikipedia tells me, "A UUID is a 128-bit number." Now that we have UInt128 in the standard library, are there type conversions or other APIs that become possible to express in modern Swift using that type which we should now add as part of this modernization?
It's a good question. I am hoping that the work on the "fully inhabited" protocols (see safe loading API for RawSpan) will provide a seamless connection between Span<UInt8> and Int128, when it's useful. That is, an Int128 is inherently Raw, and Raw is inherently UInt8. But I will leave the discussion of those points for the other thread, to avoid getting into the weeds on this one.
If if doesn't work out, we could revisit adding conveniences to this type too.
Has it been considered making lower cased the default representation from .uuidString? As I understand it, the spec states UUIDs should be represented as lowercase.
I think the default should be as spec compliant as possible. One reason it would have tangible impact is that the default being uppercase currently allows implicit identification of iOS users vs other platforms if the UUID is logged without transforming to lowercase.
Making the default match the spec and other implementations would prevent that which seems like a good thing.
A previous pitch to conform UUID to LosslessStringConvertible was accepted, but the pull requests for the proposal and implementation haven't been merged yet.
Instead of adding a lowercasedUUIDString property, you could add an initializer similar to the String.init(_:radix:uppercase:) used by binary integers.
extension String {
public init(_ uuid: UUID, uppercase: Bool)
}
I think we could simply name the string accessors lowercased() and uppercased(), mirroring the String API.
There is a strong connection between a UUID value and its string representation, so in lowercasedUUIDString I feel like both the UUID and String parts are redundant.
We can't change uuidString without risking breaking existing apps.. However this we probably could:
deprecate uuidString
make a new property, say string and make that one lowercasing.
do not provide uppercasing property/method (thus guiding users away from that). Those who want to uppercase will just call uuid.string.uppercased().
As for the name for nil - I don't think we need to religiously follow the RFC in that regards, the same way we don't want to call that constant Nil (as per the RFC).
The idiomatic spelling in Swift, if we're creating new APIs, would be as @benrimmington describes: that is, a converting initializer String(_: UUID, uppercase: Bool = false).
Looks good to me + deprecating the uuidString property.
@tera - I think your concern could be addressed by also having an initialiser that accepts an optional UUID and returns an optional String. Eg: String(_: UUID?, uppercase: Bool = false)
Whether that belongs in the standard library I’m not sure, but would be trivial to add as a convenience extension if needed.
We have precedents for having multiple ways of performing such conversions, for example, String(42) and 42.formatted(). That said, providing a single way in this case (such as String.init) is sufficient.
However, I would like to see the deprecation of uuidString being included in this pitch to better align with RFC 4122 and ITU-T X.667 in guiding users away from uppercased UUID. And to make this guidance consistent we should probably avoid introducing an option for uppercasing UUIDs in the new String.init (and thus not have its uppercase parameter).