CFArrayBSearchValues中的二进制搜索警告 [英] Binary search warning in CFArrayBSearchValues

查看:227
本文介绍了CFArrayBSearchValues中的二进制搜索警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 CFArrayBSearchValues



参考:。

  NSUInteger indexResult = [m_Locations 
indexOfObject:data
inSortedRange:NSMakeRange(0,[m_Locations count])
选项:0
usingComparator:^(id a,id b){...}];


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.

解决方案

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) { ... }];

这篇关于CFArrayBSearchValues中的二进制搜索警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆