美文网首页ios开发资源收集
CFDictionary 笔记(1)

CFDictionary 笔记(1)

作者: 70fd779f77ba | 来源:发表于2015-12-11 15:59 被阅读4156次

//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 );

相关文章

网友评论

  • 不留名的黄子嘉:大神 好久没更新了啊。。 最近在学一些篇底层的东西 比如我socket推送数据很快的情况下 我要快速去遍历设置 用这个就刚刚好 希望能介绍更对 避免踩坑。 貌似有部分是要内存管理的?

本文标题:CFDictionary 笔记(1)

本文链接:https://www.haomeiwen.com/subject/gvryhttx.html