如何将选择器声明为 iOS 属性以及接下来如何使用我的属性?

发布于 2024-12-29 01:28:48 字数 445 浏览 1 评论 0原文

我接下来写。所有使用 ARC 编写的代码

@interface MPEvent : UIImageView
@property (nonatomic, unsafe_unretained) SEL action;
@property (nonatomic, strong) id target;

@end

选择器是否以正确的方式声明?

在实现中,我接下来这样使用我的属性:

- (void)sendActionToTargetFromView:(id)view {
    [target performSelector:action withObject:view];
}

但是编译器向我显示警告
警告:语义问题:PerformSelector 可能会导致泄漏,因为其选择器未知

如何修复此警告?

I write next. All code wrote with ARC

@interface MPEvent : UIImageView
@property (nonatomic, unsafe_unretained) SEL action;
@property (nonatomic, strong) id target;

@end

Is selector declared in correct way?

In implementation I use my properties next this way:

- (void)sendActionToTargetFromView:(id)view {
    [target performSelector:action withObject:view];
}

But compiler show me a warning
warning: Semantic Issue: PerformSelector may cause a leak because its selector is unknown

How to fix this warning?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

熟人话多 2025-01-05 01:28:48

在下面的示例中,仅忽略一行代码 -Warc-performSelector-leaks,之后诊断返回到之前存在的任何状态。

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    [self.ticketTarget performSelector: self.ticketAction withObject: self];
#pragma clang diagnostic pop

pragma 警告帮助
详细说明

In the below example -Warc-performSelector-leaks is ignored for only a single line of code, after which the diagnostics return to whatever state had previously existed.

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    [self.ticketTarget performSelector: self.ticketAction withObject: self];
#pragma clang diagnostic pop

pragma warnings help
Detailed description

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文