Xcode warning "Property access results unused - getters should not be used for side effects"

ICL1901 picture ICL1901 · Mar 18, 2011 · Viewed 25.4k times · Source

I'm getting this warning when I'm calling a local routine.

My code is this:

-(void)nextLetter {
    // NSLog(@"%s", __FUNCTION__);
    currentLetter ++;
    if(currentLetter > (letters.count - 1))
    {
        currentLetter = 0;
    }
    self.fetchLetter;
}

I'm getting the warning on the self.fetchLetter statement.

That routine looks like this:

- (void)fetchLetter {
    // NSLog(@"%s", __FUNCTION__);
    NSString *wantedLetter = [[letters objectAtIndex: currentLetter] objectForKey: @"langLetter"];

    NSString *wantedUpperCase = [[letters objectAtIndex: currentLetter] objectForKey: @"upperCase"];    


.....   
}

I prefer to fix warning messages, is there a better way to write this?

Thanks!

Answer

Tom Dalling picture Tom Dalling · Mar 18, 2011

The dot notation (i.e. self.fetchLetter) is meant for properties, not for arbitrary methods. The self.fetchLetter is being interpreted as "get the 'fetchLetter' property of 'self'," which isn't what you intend.

Just use [self fetchLetter] instead.