我是新手。我正在尝试使用以下代码生成UUID ..
- (NSString *)GetUUID
{
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
//CFUUIDBytes number = CFUUIDGetUUIDBytes (theUUID);
DLog(@"Howwww :%@", theUUID);
CFRelease(theUUID);
return [(NSString *)string autorelease];
}
我在字符串中得到结果为..
NSString *result = [self GetUUID];
现在问题是我无法将其存储在我的sqlite数据库中。我正在尝试使用语句
将其存储在VARCHAR
列中
sqlite3_bind_text(compiledStatement, 10, [_idNumber UTF8String], -1, SQLITE_TRANSIENT);
请有人帮帮我。感谢..
答案 0 :(得分:0)
这是一个将UUID作为NSString
返回的方法,只需将其作为字符串保存在数据库中。
- (NSString *)newUUID
{
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
return (NSString *)string;
}
如果你需要一个c字符串:
NSString *uuidString = [self newUUID];
const char *uuidCString = [uuidString cStringUsingEncoding:NSASCIIStringEncoding];