Binary search warning in CFArrayBSearchValues

久未见 提交于 2019-12-12 02:34:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!