There are a couple good examples on SO about CFUUID, notably this one:
How to create a GUID/UUID using the iPhone SDK
But it was made for pre-ARC code, and I’m not a CF junkie (yet), so can someone provide example code that works with ARC?
+ (NSString *)GetUUID
{
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
return [(NSString *)string autorelease];
}
You want a “bridged transfer”:
The Transitioning to ARC Guide says
However! You should also rename your method. ARC uses method name conventions to reason about retain counts, and methods that start with
getin Cocoa have a specific meaning involving passing a buffer in for it to get filled with data. A better name would bebuildUUIDor another word that describes the use of the UUID:pizzaUUIDorbearUUID.