yonasstephen
yonasstephen

Reputation: 2725

What is the difference between NSMutableDictionary and CFDictionaryRef?

I am trying to get the EXIF attachment from an image captured using AVCaptureDevice like this:

CFDictionaryRef exifAttachments = (CFDictionaryRef)CMGetAttachment(buf, kCGImagePropertyExifDictionary, NULL);

NSMutableDictionary *exifAttachment = (__bridge NSMutableDictionary*)CMGetAttachment(buf, kCGImagePropertyExifDictionary, NULL);

Both seem to return the same result, although the NSMutableDictionary one needs __bridge to cast the type. What are the differences between them? When should I use which?

Upvotes: 0

Views: 1676

Answers (1)

doptimusprime
doptimusprime

Reputation: 9415

In the first place, CFDictionaryRef is non-mutable whereas NSMutableDictionary is mutable (can be modified).

You cannot replace one with another. However, CFMutableDictionaryRef can be converted to NSMutableDicionary and that conversion is toll-free bridged conversion. For CFDictionaryRef, equivalent object is NSDicionary.

If you are writing your program using pure C/C++, then use Core Foundation's CFDicionary. For Objective-C, you can use both.

Below these links can help you.

Relationship between CFMutableDictionary and NSMutableDictionary

NSMutableDictionary vs CFMutableDictionary

Upvotes: 1

Related Questions