多种方法名为' count'发现了警告

时间:2017-12-28 07:21:04

标签: ios objective-c warnings xcode-workspace

enter image description here嗨,我刚刚更新了我的dropbox api,但我认为这不应该导致这个问题但是在更新之后我正在使用xcode 9.2在我的项目中加入waring。 知道怎么摆脱这个警告吗?

  

多种名为' count'结果

请参阅方法调用的代码和附加屏幕截图。

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [[thumbImagesCollectionArray objectAtIndex:collectionView.tag-1] count];
}

1 个答案:

答案 0 :(得分:1)

在致电[thumbImagesCollectionArray objectAtIndex:collectionView.tag-1]之前,您应该将NSMutableArray强制转换为count

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    [(NSMutableArray *)[thumbImagesCollectionArray objectAtIndex:collectionView.tag-1] count];
}

据我所知,在编译时,调用[thumbImagesCollectionArray objectAtIndex:collectionView.tag-1]时返回的对象类型是不知道的。并且它不知道应该在此对象上调用count方法。这就是我们警告的原因。

要修复它,将对象返回到NSMutableArray,以便编译器知道应该调用什么方法。

相关问题