I am a newbie here. I am trying to generate UUIDs using the following code开发者_如何学JAVA..
- (NSString *)GetUUID
{
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
//CFUUIDBytes number = CFUUIDGetUUIDBytes (theUUID);
DLog(@"Howwww :%@", theUUID);
CFRelease(theUUID);
return [(NSString *)string autorelease];
}
I am getting the result in a string as..
NSString *result = [self GetUUID];
Now the problem is I am unable to store it inside my sqlite database. I am trying to store it in a VARCHAR
column using the statement
sqlite3_bind_text(compiledStatement, 10, [_idNumber UTF8String], -1, SQLITE_TRANSIENT);
Please can anyone help me out here. Thanks..
Here is a method that return the UUID as a NSString
, just save it in the db as a string.
- (NSString *)newUUID
{
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
return (NSString *)string;
}
If you need a c string:
NSString *uuidString = [self newUUID];
const char *uuidCString = [uuidString cStringUsingEncoding:NSASCIIStringEncoding];
精彩评论