iosobjective-cwarningsxcode-workspace

Multiple methods named 'count' found warning


enter image description herehi, I just updated my dropbox api but i think this shouldn't cause this issuebut after updating i am getting waring in my project when i build it using in xcode 9.2. Any idea how to get rid of this warning?

Multiple methods named 'count' found

Please see the code and attached screenshot for methods calls.

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

Solution

  • You should cast [thumbImagesCollectionArray objectAtIndex:collectionView.tag-1] to NSMutableArray before calling count.

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

    As I understand, at the compile time, type of object returned when calling [thumbImagesCollectionArray objectAtIndex:collectionView.tag-1] isn't known. And it don't know what count method should be called on this object. That's why we have warning.

    To fix it, cast object returned to NSMutableArray so compiler will know what method exactly should be called.