4

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

2 Answers2

12

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];
mipadi
  • 398,885
  • 90
  • 523
  • 479
3

For an autoreleased version, use

NSMutableArray* data = [NSMutableArray arrayWithArray: (NSArray*) myCFArrayRef];
Kenn Cal
  • 3,659
  • 2
  • 17
  • 18