0

I'm trying to filter my contacts based on alphabets, something like this

NSArray *sectionArray = [contactAdd filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", [self.friendListSection objectAtIndex:section]]];

But here the problem is contactAdd is not a regular array its CFArray defined as

@property  CFArrayRef contactAdd;

So this code wont work, is there any alternative to use the above code for CFArray or any other solution to get the desired result??

Note:I dont want to change my contactAdd to regular array, I need to use CFArray only

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Francis F
  • 3,157
  • 3
  • 41
  • 79

1 Answers1

4
NSArray *array = (NSArray *)CFBridgingRelease(self.contactAdd);
NSArray *sectionArray = [array filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", [self.friendListSection objectAtIndex:section]]];

Quoting the documentation (emphasis added)

CFArray is “toll-free bridged” with its Cocoa Foundation counterpart, NSArray. This means that the Core Foundation type is interchangeable in function or method calls with the bridged Foundation object. Therefore, in a method where you see an NSArray * parameter, you can pass in a CFArrayRef, and in a function where you see a CFArrayRef parameter, you can pass in an NSArray instance. This also applies to concrete subclasses of NSArray. See “Toll-Free Bridged Types” for more information on toll-free bridging.

Extra information about bridged casting: NSString to CFStringRef and CFStringRef to NSString in ARC?

Community
  • 1
  • 1
Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235