CFPropertyListCreateDeepCopy 无法处理包含 NSNull 的数组/字典 [英] CFPropertyListCreateDeepCopy fails to process array / dictionary containing NSNull

查看:52
本文介绍了CFPropertyListCreateDeepCopy 无法处理包含 NSNull 的数组/字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,此示例代码有效:

For some reason this sample code works:

NSArray *immutable = @[ @"a", @"b", @"c" ];
NSMutableArray *mutable = (__bridge  id)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge  CFArrayRef)immutable, kCFPropertyListMutableContainers);

并且此代码生成 nil 作为转换的结果:

and this code produces nil as a result of the conversion:

NSArray *immutable = @[ @"a", [NSNull null], @"c" ];
NSMutableArray *mutable = (__bridge  id)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge  CFArrayRef)immutable, kCFPropertyListMutableContainers);

我试图找到在使用此函数时不允许提及 NSNull 的任何内容.我怀疑这与方法检查属性是否可变的方式有关,但我无法用事实来证明这一点.

I tried to find any mention of NSNull not being allowed when using this function. I have a suspicion that it has something to do with the way method examines whether property is mutable or not, but I can't really back that up with facts.

有什么想法吗?

推荐答案

苹果开发者论坛的好心人指出,问题是属性列表结构对它可以使用的数据类型相当严格.NSNull 不是允许的之一.

As kind people from apple developer forum pointed out the issue is that Property List Structure is rather strict about data types it can work with. NSNull is not one of allowed ones.

来自 苹果文档:

属性列表由基本的 Core Foundation 类型 CFStringCFNumberCFBooleanCFDateCFData.

Property lists are constructed from the basic Core Foundation types CFString, CFNumber, CFBoolean, CFDate, and CFData.

这篇关于CFPropertyListCreateDeepCopy 无法处理包含 NSNull 的数组/字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆