gpt4 book ai didi

swift - 快速检查 UUID 版本

转载 作者:可可西里 更新时间:2023-11-01 00:54:19 26 4
gpt4 key购买 nike

有没有办法检查 UUID 版本?我知道 UUID().uuidString 是版本 4。我有一个来自服务器的变量,它在 UUID 版本 1 中。

现在我想检查 UUID 的版本并决定我的操作。

最佳答案

版本 4 UUID 的格式为 xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx,其中 x 是任何十六进制数字,y 是 8、9、A 或 B 之一,如下所述: How to determine if a string is a valid v4 UUID?

如果您只使用版本 4 和版本 1,那么您可以执行以下操作:

func checkUUIDVersion(uuid: String) -> Int {
let regx = "^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}"
if uuid.uppercased().range(of: regx, options: .regularExpression, range: nil, locale: nil) != nil {
return 4;
}
return 1;
}

关于swift - 快速检查 UUID 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53848236/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com