xcode 如何为 NSMutableArray 制作 CFArrayRef
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8761461/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make an CFArrayRef to an NSMutableArray
提问by Fabian Kr?ger
This is my Code to create the CFArrayRef. I want to know how to make it to an NSMutableArray. I need it for my TableViewController. Or is there another way to use the CFArrayRef in the TableViewController?
这是我创建 CFArrayRef 的代码。我想知道如何使它成为 NSMutableArray。我的 TableViewController 需要它。或者还有另一种方法可以在 TableViewController 中使用 CFArrayRef 吗?
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef arrayOfAllPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
回答by mipadi
A CFArrayRef
is toll-free bridged to NSArray *
, so you can cast it as such and then create a mutable copy:
ACFArrayRef
是免费桥接到 的NSArray *
,因此您可以将其转换为这样,然后创建一个可变副本:
NSMutableArray *data = [(NSArray *) myCFArrayRef mutableCopy];
回答by Kenn Cal
For an autoreleased version, use
对于自动发布版本,请使用
NSMutableArray* data = [NSMutableArray arrayWithArray: (NSArray*) myCFArrayRef];