Graphics Programs Reference
In-Depth Information
how memory is allocated. In practice, you pass kCFAllocatorDefault and let the
system make that choice.
Once created, a CFUUIDRef is just an array of bytes and, if represented as a string, will
look something like this:
28153B74-4D6A-12F6-9D61-155EA4C32167
This UUID will be used in two ways: it will be the key in the BNRImageStore 's dic-
tionary and in a later chapter, it will be the name of the image file on the filesystem. Be-
cause keys in a dictionary and paths on the filesystem are typically strings, we want to
represent the UUID as a string instead of an array of bytes.
You can create a string object from a CFUUIDRef by calling the C function
CFUUIDCreateString . In DetailViewController.m , add the following line of
code in imagePickerController:didFinishPickingMediaWithInfo: .
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
CFUUIDRef newUniqueID = CFUUIDCreate (kCFAllocatorDefault);
// Create a string from unique identifier
CFStringRef newUniqueIDString =
CFUUIDCreateString (kCFAllocatorDefault, newUniqueID);
Notice that newUniqueIDString 's type is CFStringRef . The imageKey property
of BNRItem is an NSString . Clearly, you need some way to move between
CFStringRef and NSString to set the imageKey property.
Fortunately, many classes in Core Foundation are toll-free bridged with their Objective-C
counterpart. For example, CFStringRef is toll-free bridged with NSString ; CFAr-
rayRef with NSArray . Instances of classes that are toll-free bridged look exactly the
same as their counterpart in memory. Therefore, you can use a simple C-style typecast to
treat a toll-free bridged Core Foundation object as an Objective-C object.
Typecast newUniqueIDString and set it as the imageKey of the selected BNRItem
in imagePickerController:didFinishPickingMediaWithInfo: . Also,
place this image in the BNRImageStore .
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
CFUUIDRef newUniqueID = CFUUIDCreate (kCFAllocatorDefault);
Search WWH ::




Custom Search