SSCheckBoxView icon indicating copy to clipboard operation
SSCheckBoxView copied to clipboard

PerformSelector may cause a leak because its selector is unknown

Open Spokane-Dude opened this issue 10 years ago • 5 comments

Getting the above warning on this line of code in the touchesEnded method:

 [delegate performSelector: stateChangedSelector withObject:self];

I don't want to change anything just in case it causes more damage. I'm using XCode 5.1.

Spokane-Dude avatar Apr 05 '14 15:04 Spokane-Dude

It shouldn't do any harm if you set the delegate and the selector correctly.

ahmetardal avatar Apr 06 '14 16:04 ahmetardal

It's not in my code.. it's in your code; I'm afraid that it will become a build error in the not too distant future. Can you not correct it?

Spokane-Dude avatar Apr 06 '14 16:04 Spokane-Dude

Just use the state changed block, don't use the delegate then.

SSCheckBoxView *cbv = ...
[cbv setStateChangedBlock:^(SSCheckBoxView *v) {
    NSLog(@"checkbox state: %d", v.checked);
}];

ahmetardal avatar Apr 06 '14 17:04 ahmetardal

I think we're not talking about the same code... this is the code in your SSCheckedBoxView.m, method is: touchesEnded: withEvent:

    if (CGRectContainsPoint(validTouchArea, point)) {
        checked = !checked;
        [self updateCheckBoxImage];
        if (delegate && stateChangedSelector) {
            [delegate performSelector: stateChangedSelector withObject:self];  //  <----warning here
        }
        else if (stateChangedBlock) {
            stateChangedBlock(self);
        }
    }

The build warning is on the line indicated with <---warning here

Spokane-Dude avatar Apr 06 '14 17:04 Spokane-Dude

I'll update it when I've time. For now just use the block and don't set the delegate.

ahmetardal avatar Apr 06 '14 17:04 ahmetardal