How to make an CFArrayRef to an NSMutableArray
Asked Answered
P

2

5

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?

ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef arrayOfAllPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
Plot answered 6/1, 2012 at 16:59 Comment(0)
C
13

A CFArrayRef is toll-free bridged to NSArray *, so you can cast it as such and then create a mutable copy:

NSMutableArray *data = [(NSArray *) myCFArrayRef mutableCopy];
Cookgeneral answered 6/1, 2012 at 17:3 Comment(2)
How about type casting NSMutableArray to CFArrayRefUnlovely
If you use ARC, I think you need to use this instead: (__bridge NSArray *)Octavie
C
3

For an autoreleased version, use

NSMutableArray* data = [NSMutableArray arrayWithArray: (NSArray*) myCFArrayRef];
Coles answered 18/7, 2012 at 3:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.