PerformSelector 可能导致泄漏 - 更好的解决方案 [英] PerformSelector may cause a leak - Better solution

查看:35
本文介绍了PerformSelector 可能导致泄漏 - 更好的解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义 BackBarButton,我有一个属性来存储在某些情况下可以更改的选择器.所以我不能很顺利地使用委托.

I have a custom BackBarButton where I have a property to store a selector which can change in some cases. So I can't use delegation really smoothly.

如何在不将工作流程"更改为委托的情况下消除此警告?该属性是通过使用此定义的:

What can I do to get rid of this warning without changing the 'workflow' to delegation? The property is defined by using this:

@property (nonatomic, strong) id<SPUniversalBackBarButtonItemDelegate> delegate;
@property (nonatomic, assign) SEL delegationSelector;

我也尝试使用此代码,但它显示没有已知的选择器实例方法..."和指向 IMP 的 Objective-C 指针的隐式对话"...

I also tried to use this code, but it says 'No known instance method for selector...' and 'Implicit conversation of an Objective-C pointer to IMP'...

IMP imp = [[self delegate] methodForSelector:[self delegationSelector]];
void (*func)(id, SEL) = (void *)imp;
func([self delegate], [self delegationSelector]);

推荐答案

您可以在协议声明中公开您的方法.然后你就可以在不需要选择器的情况下调用它.你不会收到那个警告.

You can expose your method in the protocol declaration. Then you will be able to call it without the need of a selector. And you won't have that warning.

如果你只是想摆脱警告:

if you just want to get rid of the warning:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
        //code here will ignore the warning
#pragma clang diagnostic pop

这篇关于PerformSelector 可能导致泄漏 - 更好的解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆