Skip to content

Conversation

stephencelis
Copy link
Member

No description provided.

@stephencelis stephencelis requested a review from mbrandonw March 23, 2023 04:50
@acosmicflamingo
Copy link
Contributor

Oh clever! I memorized 8-4-4-4-12 for creating UUIDs but looks like this will be helpful :)

}

extension UUID {
public init(_ intValue: Int) {
Copy link
Collaborator

@tgrapperon tgrapperon Mar 23, 2023

Choose a reason for hiding this comment

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

Is it working as expected if we pass -1?
Otherwise, we could restrict to UInt or take the absolute value.

EDIT: it generates 0000ffffffff, so this is not crashing, but that's maybe a little counterintuitive

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I'd expect -1 to be all FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF. Might make more sense to force users to pass it an unsigned integer.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it working as expected if we pass -1?

I think we'd consider -1 "undefined" and leave it at that.

Otherwise, we could restrict to UInt or take the absolute value.

We prefer Int to UInt as Swift tends to do (using it for Array.count, Array.index, etc.).

We're open to improvements if folks wanna PR, but seeing as this is primarily a test helper, we're not too worried about it covering edge cases.

@stephencelis stephencelis merged commit 0b18a15 into main Mar 23, 2023
@stephencelis stephencelis deleted the uuid-int-init branch March 23, 2023 17:18
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