Swift: UUID to odd or even number
By somaria
2022-12-15
import Cocoa /* Create a uuid */ let uuid = UUID().uuidString print(uuid) /* remove dashes from uuid */ let uuidWithoutDashes = uuid.replacingOccurrences(of: "-", with: "") print(uuidWithoutDashes) /* remove all characters from the uuid */ let uuidWithoutAllCharacters = uuidWithoutDashes.replacingOccurrences(of: "[A-Z]", with: "", options: .regularExpression) print(uuidWithoutAllCharacters) /* get the last character from the uuid */ let lastCharacter = uuidWithoutAllCharacters.last print(lastCharacter!) /* check if the last character is a even or odd number */ let isEven = Int(String(lastCharacter!))! % 2 == 0 print(isEven)

Output

985BCADD-D907-4D19-B48A-22A1D8067704

985BCADDD9074D19B48A22A1D8067704

985907419482218067704

4