Generating a UUID

Listing 1-12 shows you how to generate a UUID using Core Foundation Utility Services functions. Core Foundation Plug-in services uses UUIDs to uniquely identify types, interfaces, and factories.

Listing 1-12 Generating a UUID

CFUUIDRef       myUUID;
CFStringRef     myUUIDString;
char            strBuffer[100];

myUUID = CFUUIDCreate(kCFDefaultAllocator);
myUUIDString = CFUUIDCreateString(kCFDefaultAllocator, myUUID);

// This is the safest way to obtain a C string from a CFString.
CFStringGetCString(myUUIDString, strBuffer, 100, kCFStringEncodingASCII);
printf("My UUID is: %s", strBuffer);

After printing the UUID to standard out, you can just copy and paste the string into your header file or property list.


© 2000 Apple Computer, Inc. (Last Updated 04 April 00)