CFPropertyListCreateDeepCopy fails to process array / dictionary containing NSNull
2015-02-03 09:29
841 查看
For some reason this sample code works:
and this code produces
a result of the conversion:
I tried to find any mention of
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.
Any ideas?
activeoldestvotes
转载:http://stackoverflow.com/questions/12159205/cfpropertylistcreatedeepcopy-fails-to-process-array-dictionary-containing-nsnu
转换代码记录备份。注意:如果数据中有null,转换会返回nil
// NSArray --->>> NSMutableArray
NSMutableArray *mutableArray = CFBridgingRelease(CFPropertyListCreateDeepCopy(NULL, (__bridge CFPropertyListRef)(arrayData), kCFPropertyListMutableContainersAndLeaves));
//NSDictionary--->>> NSMutableDictionary
NSMutableDictionary *mutableDict = (NSMutableDictionary *)CFBridgingRelease(CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge CFPropertyListRef)(dictData), kCFPropertyListMutableContainersAndLeaves));
NSArray *immutable = @[ @"a", @"b", @"c" ]; NSMutableArray *mutable = (__bridge id)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge CFArrayRef)immutable, kCFPropertyListMutableContainers);
and this code produces
nilas
a result of the conversion:
NSArray *immutable = @[ @"a", [NSNull null], @"c" ]; NSMutableArray *mutable = (__bridge id)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge CFArrayRef)immutable, kCFPropertyListMutableContainers);
I tried to find any mention of
NSNullnot
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.
Any ideas?
1 Answer
activeoldestvotesup vote2down voteaccepted | 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. NSNullis not one of allowed ones. From apple docs: Property lists are constructed from the basic Core Foundation types CFString, CFNumber, CFBoolean, CFDate, and CFData. |
转换代码记录备份。注意:如果数据中有null,转换会返回nil
// NSArray --->>> NSMutableArray
NSMutableArray *mutableArray = CFBridgingRelease(CFPropertyListCreateDeepCopy(NULL, (__bridge CFPropertyListRef)(arrayData), kCFPropertyListMutableContainersAndLeaves));
//NSDictionary--->>> NSMutableDictionary
NSMutableDictionary *mutableDict = (NSMutableDictionary *)CFBridgingRelease(CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge CFPropertyListRef)(dictData), kCFPropertyListMutableContainersAndLeaves));
相关文章推荐
- copy string array to string list
- Attempt to set a non-property-list object null as an NSUserDefaults
- CFReadStreamCopyProperty() returns NULL?
- js Array to C# List<Dictionary>(js 传参 自定义类列表 到C#)
- 同一台PC安装了多版本python,且均配置了环境变量,pip list的时候提示:failed to create process
- 双空结束字符串的拷贝问题 How to copy the pairs of NULL-terminated strings
- C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue
- C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- How to deal with javadoc createProcess issue?
- C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue
- 关于java.lang.ClassCastException: org.jbpm.jpdl.internal.model.JpdlProcessDefinition cannot be cast to java.util.List
- JAVA学习提高之---- List toArray学到的
- C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue
- C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- 如何使用List.toArray()转换为数组对象
- C# 集合类 Array,Arraylist,List,Hashtable,Dictionary,Stack,Queue学习资料
- C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue
- C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue
- C# 集合类 Array, Arraylist, List, Hashtable, Dictionary, Stack, Queue