如何在 SQLITE iPhone 中生成唯一的 GUID 36 个字符 [英] How to generate unique GUID 36 chars in SQLITE iPhone

查看:91
本文介绍了如何在 SQLITE iPhone 中生成唯一的 GUID 36 个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个唯一且具有主键的表.我知道在 sqlite 中我们可以开发唯一的 AUTOINCREMENT ID SQL AUTOINCREMENT,但是是否可以生成唯一的 GUID这是 36 个字符长.这样做的唯一原因是让它更加独特.

I am trying to create a table which is unique and has primary key. I know in sqlite we can develop Unique AUTOINCREMENT ID SQL AUTOINCREMENT, but is it possible to generate Unique GUID which is 36 chars long. The only reason to do that is to make it more unique.

推荐答案

这是我用于 UUID 的一小段代码(我什至可能在 Stack Overflow 上找到了它)...

This is the bit of code I use for UUIDs (I may have even found it here on Stack Overflow)...

+ (NSString *)GetUUID
{
    CFUUIDRef theUUID = CFUUIDCreate(NULL);
    CFStringRef string = CFUUIDCreateString(NULL, theUUID);
    CFRelease(theUUID);
    return [(NSString *)string autorelease];
}

我不知道生成的 UUID 多长时间,因为在我使用它的方式中我不在乎所以也许可以通过将结果传递到 NSLog 调用来检查.

I don't know how long the UUIDs generated are because in the ways I use it I don't care so perhaps check that by passing the result into a NSLog call.

HTH,佩德罗 :)

这篇关于如何在 SQLITE iPhone 中生成唯一的 GUID 36 个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆