2011-03-28 44 views
0

我使用的是CFArrayBSearchValuesCFArrayBSearchValues中的二進制搜索警告

編號:http://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFArrayRef/Reference/reference.html#//apple_ref/doc/uid/20001192-CH201-F10956

它的工作原理成功,但編譯器給我的第一個參數警告:

CFIndex indexResult = CFArrayBSearchValues( 
         m_Locations, 
         CFRangeMake(0, [m_Locations count]), 
         data, 
         PGPlaceDataCompare, nil); 

enter image description here

CFArrayBSearch期待作爲第一個參數的CFArrayRef。我的m_LocationsNSMutableArray

如何解決此警告?我需要做任何強制轉換爲CFArrayRef的NSMutableArray?

謝謝。

回答

2

是的。只需將NSMutableArray投射到CFArrayRef。

CFIndex indexResult = CFArrayBSearchValues( 
         (CFArrayRef)m_Locations, 
         CFRangeMake(0, [m_Locations count]), 
         data, 
         PGPlaceDataCompare, NULL); 

在iOS 4.0或更高版本,你可以使用Objective-C method -indexOfObject:inSortedRange:options:usingComparator:代替。

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

這很容易!謝謝 – elp 2011-03-28 09:23:06