CFDictionary 笔记(1)

//TMD不支持TOC·······

1.CFDictionaryCreate/CFDictionaryCreateMutable / CFDictionaryCreateCopy //创建不可变/可变字典。

CFDictionaryCreate ( CFAllocatorRef allocator, 
                      const void **keys, 
                      const void **values, 
                      CFIndex numValues, 
                      const CFDictionaryKeyCallBacks*keyCallBacks, 
                      const CFDictionaryValueCallBacks*valueCallBacks );
参数 类型 释义
allocator CFAllocatorRef 为新字典分配内存。通过NULL或kCFAllocatorDefault使用当前默认的分配器。
keys void * key的数组。如果numValues参数为0,则这个值可能是NULL。这个函数没有改变或释放这个数组。该值必须是有效的C数组。
values void * value的数组(同上)。
numValues CFIndex 键值对数目。>=0 && >=实际数目。
keyCallBacks CFDictionaryKeyCallBacks 键的回调。
valueCallBacks CFDictionaryValueCallBacks 值的回调。

例:

CFStringRef keys[2];

keys[0] = CFSTR("key1");

keys[1] = CFSTR("key2");

CFStringRef values[2];

values[0] = CFSTR("this is the first string");

values[1] = CFSTR("this is the second string");

CFDictionaryRef myDictionaryRef = CFDictionaryCreate(kCFAllocatorDefault,
                                                    (void*)keys,
                                                    (void*)values,
                                                    2,
                                                    &kCFTypeDictionaryKeyCallBacks,
                                                    &kCFTypeDictionaryValueCallBacks);

2.CFDictionaryGetCount //返回键值对数目。

CFIndex CFDictionaryGetCount ( CFDictionaryRef theDict );

3.CFDictionaryContainsValue/Key //检测一个值/键是否包含在字典内。

Boolean CFDictionaryContainsValue ( CFDictionaryRef theDict, const void *value);
Boolean CFDictionaryContainsKey ( CFDictionaryRef theDict, const void *key );

4.CFDictionaryGetKeysAndValues //返回一个 keys的C数组 和 一个vlaue的C数组。

void CFDictionaryGetKeysAndValues ( CFDictionaryRef theDict , 
                                    const void ** keys , 
                                    const void ** values );

5.CFDictionaryApplyFunction //对所有键值对执行一个方法。

void CFDictionaryApplyFunction ( CFDictionaryRef theDict ,
                                 CFDictionaryApplierFunction applier , 
                                 void * context );

你可能感兴趣的:(CFDictionary 笔记(1))