问题
i'm using CFArrayBSearchValues
.
Ref: http://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFArrayRef/Reference/reference.html#//apple_ref/doc/uid/20001192-CH201-F10956
It works successfully but compiler show me a warning on first parameter:
CFIndex indexResult = CFArrayBSearchValues(
m_Locations,
CFRangeMake(0, [m_Locations count]),
data,
PGPlaceDataCompare, nil);

CFArrayBSearch
expect as first parameter an CFArrayRef
.
My m_Locations
is an NSMutableArray
.
How to resolve this warning? I need to do any cast to NSMutableArray to CFArrayRef?
thanks.
回答1:
Yes. Just cast the NSMutableArray to CFArrayRef.
CFIndex indexResult = CFArrayBSearchValues(
(CFArrayRef)m_Locations,
CFRangeMake(0, [m_Locations count]),
data,
PGPlaceDataCompare, NULL);
On iOS 4.0 or later you could use the Objective-C method -indexOfObject:inSortedRange:options:usingComparator: instead.
NSUInteger indexResult = [m_Locations
indexOfObject:data
inSortedRange:NSMakeRange(0, [m_Locations count])
options:0
usingComparator:^(id a, id b) { ... }];
来源:https://stackoverflow.com/questions/5456633/binary-search-warning-in-cfarraybsearchvalues