Perform ARC Warning

Possible duplicate:
performSelector may cause a leak because its selector is unknown

I have this code in non-ARC that works without errors or warnings:

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents { // Only care about value changed controlEvent _target = target; _action = action; } - (void)setValue:(float)value { if (value > _maximumValue) { value = _maximumValue; } else if (value < _minimumValue){ value = _minimumValue; } // Check range if (value <= _maximumValue & value >= _minimumValue) { _value = value; // Rotate knob to proper angle rotation = [self calculateAngleForValue:_value]; // Rotate image thumbImageView.transform = CGAffineTransformMakeRotation(rotation); } if (continuous) { [_target performSelector:_action withObject:self]; //warning here } } 

However, after converting to a project in ARC, I get the following warning:

"Performing a selector may cause a leak because its selector is unknown."

I would really like the ideas on how to revise my code accordingly.

+7
ios objective-c xcode automatic-ref-counting
Aug 10 2018-12-12T00:
source share
1 answer

The only thing I found to avoid the warning was to suppress it. You can disable it in the build settings, but I prefer to just use pragmas to disable it, where I know it is false.

 # pragma clang diagnostic push # pragma clang diagnostic ignored "-Warc-performSelector-leaks" [_target performSelector:_action withObject:self]; # pragma clang diagnostic pop 

If you get an error in several places, you can define a macro to make it easier to suppress the warning:

 #define SuppressPerformSelectorLeakWarning(Stuff) \ do { \ _Pragma("clang diagnostic push") \ _Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \ Stuff; \ _Pragma("clang diagnostic pop") \ } while (0) 

You can use the macro as follows:

 SuppressPerformSelectorLeakWarning([_target performSelector:_action withObject:self]); 
+40
Aug 10 2018-12-12T00:
source share



All Articles