Re: Strings from UUID
Re: Strings from UUID
- Subject: Re: Strings from UUID
- From: Douglas Davidson <email@hidden>
- Date: Mon, 12 Aug 2002 11:17:42 -0700
On Friday, August 9, 2002, at 01:05 PM, j o a r wrote:
Stoopid question perhaps, but here goes: With regards to balancing the
retain count on the string, would this also work?
@implementation NSString (Additions)
+ (NSString *) uniqueString
{
NSString *uString = (NSString
*)CFUUIDCreateString(kCFAllocatorDefault,
CFUUIDCreate(kCFAllocatorDefault));
return [uString autorelease];
}
@end
...or would you need to have a CFRelease()?
Yes, when we say that CFStrings and NSStrings are toll-free bridged, we
mean that they can be used interchangeably. So yes, it is OK to use
the -autorelease or -release methods on a CFString instead of calling
CFRelease(). But you probably would want to release the UUID in the
example above.
For reference, here is the code that /usr/bin/uuidgen uses to create
and print a new UUID:
CFUUIDRef uuid = CFUUIDCreate(NULL);
CFStringRef uuidStr = CFUUIDCreateString(NULL, uuid);
char buffer[256];
if (CFStringGetCString(uuidStr, buffer, 256,
kCFStringEncodingASCII)) {
printf("%s\n", buffer);
}
CFRelease(uuidStr);
CFRelease(uuid);
Douglas Davidson
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.