Bruce
Bruce

Reputation: 361

Why lowercase uuid?

I’m considering using uuid to differentiate my swift app, and looked around online for how to achieve it. While searching, I often found people lowercase the uuid such as:

let uuid = NSUUID().UUIDString.lowercaseString

Wouldn’t lowercasing the uuid be unnecessary or make it less random?

Upvotes: 17

Views: 9504

Answers (3)

rob mayoff
rob mayoff

Reputation: 385500

It is not less random, because UUIDs are not case-sensitive. UUIDs are 128-bit numbers, and in string form they are represented using hexadecimal digits. ‘A’ and ‘a’ are the same digit.

Standards such as ITU-T X.667 and RFC 4122 require them to be formatted using lower-case letters, but also require parsers to accept upper-case letters.

The NSUUID class and UUID struct use upper-case letters when formatting. Long ago, someone either got it wrong, or made the decision before the choice of lower-case letters was standardized. Apple won't change it now because doing so could break existing code that relies on the use of upper-case letters.

On Apple platforms, the UUID formatting code, unparse.c, is written in C, and (according to the copyright) was originally written by Theodore T'so in 1996 or 1997. But the code uses upper-case letters because UUID_UNPARSE_DEFAULT_UPPER is defined in uuid-config.h.

Upvotes: 22

Developer
Developer

Reputation: 405

Because it is required by international standards

You may find the information here

6.5.4 Software generating the hexadecimal representation of a UUID shall not use upper case letters. NOTE – It is recommended that the hexadecimal representation used in all human-readable formats be restricted to lower-case letters.

Upvotes: 12

Russell
Russell

Reputation: 17719

The naming conventions for variable names are to be lower case (even for acronyms):

  • using uppercase for types (and protocols), lowercase for everything else

Here is a Swift programming style guide for reference: https://github.com/raywenderlich/swift-style-guide

It also refers to the following Swift API Design guide: https://swift.org/documentation/api-design-guidelines/

Upvotes: -3

Related Questions