• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Strings from UUID
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Re: Strings from UUID (From: j o a r <email@hidden>)

  • Prev by Date: Drawing hidden NSWindow to NSImage then to a NSView
  • Next by Date: Re: NSBorderlessWindowMask'ed windows and the Window Menu
  • Previous by thread: Re: Strings from UUID
  • Next by thread: Re: Strings from UUID
  • Index(es):
    • Date
    • Thread