Objective c 性能选择器电弧警告
可能重复:Objective c 性能选择器电弧警告,objective-c,ios,xcode,automatic-ref-counting,Objective C,Ios,Xcode,Automatic Ref Counting,可能重复: 我在非ARC中有此代码,它可以在没有错误或警告的情况下工作: - (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents { // Only care about value changed controlEvent _target = target; _action = action; } - (void)setValue:
我在非ARC中有此代码,它可以在没有错误或警告的情况下工作:
- (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
}
}
-(void)addTarget:(id)目标操作:(SEL)controlEvents的操作:(UIControlEvents)controlEvents
{
//只关心值更改的controlEvent
_目标=目标;
_行动=行动;
}
-(无效)设置值:(浮动)值
{
如果(值>最大值)
{
值=_最大值;
}否则如果(值<_最小值){
值=_最小值;
}
//检查范围
如果(值=_最小值)
{
_价值=价值;
//将旋钮旋转到适当的角度
旋转=[self calculateAngleForValue:_值];
//旋转图像
thumbImageView.transform=CGAffineTransformMakeRotation(旋转);
}
如果(连续)
{
[\u target performSelector:\u action with object:self];//此处有警告
}
}
但是,在我将项目转换为圆弧后,我收到以下警告:
“执行选择器可能导致泄漏,因为其选择器未知。”
我希望您能提供一些相应的修改代码的建议。我发现避免警告的唯一方法就是抑制警告。您可以在构建设置中禁用它,但我更喜欢在我知道它是虚假的地方使用pragmas来禁用它
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[_target performSelector:_action withObject:self];
# pragma clang diagnostic pop
如果在多个地方出现错误,可以定义宏以更容易地抑制警告:
#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)
可以像这样使用宏:
SuppressPerformSelectorLeakWarning([_target performSelector:_action withObject:self]);
谢谢你,罗布。你知道这上面有没有雷达吗?大卫明:大卫蒙特我还没有提交雷达。我不知道其他人可能提交了什么雷达。