ARC编译器收到以下警告:
"performSelector may cause a leak because its selector is unknown".
Run Code Online (Sandbox Code Playgroud)
这是我正在做的事情:
[_controller performSelector:NSSelectorFromString(@"someMethod")];
Run Code Online (Sandbox Code Playgroud)
为什么我会收到此警告?我理解编译器无法检查选择器是否存在,但为什么会导致泄漏?我怎样才能更改我的代码,以便我不再收到此警告?
我发现它UIButtons不能很好地工作SKScene,所以我试图子类化SKNode来制作一个按钮SpriteKit.
我希望它工作的方式是,如果我初始化一个按钮SKScene并启用触摸事件,那么按钮将在我SKScene按下时调用我的方法.
我很感激任何能让我找到解决这个问题的建议.谢谢.
我在我的代码中有一个与ARC自动插入objc_retains有关的奇怪崩溃.
我有以下两个类:
@interface MenuItem : NSObject
@property (weak, nonatomic) id target;
@property (unsafe_unretained, nonatomic) SEL action;
@property (strong, nonatomic) id object;
- (instancetype)initWIthTarget:(id)target action:(SEL)action withObject:(id)object;
- (void)performAction;
@end
@implementation MenuItem
- (void)performAction
{
if (self.target && self.action)
{
if (self.object)
{
[self.target performSelector:self.action withObject:self.object];
}
else
{
[self.target performSelector:self.action];
}
}
}
@end
@interface Widget : NSObject
- (void)someMethod:(id)sender;
@end
Run Code Online (Sandbox Code Playgroud)
在某些时候,我实例化一个MenuItem:
MenuItem *item = [MenuItem alloc] initWithTarget:widget action:@selector(someMethod:) object:nil];
Run Code Online (Sandbox Code Playgroud)
然后我performAction在其他地方调用菜单项:
[item performAction];
Run Code Online (Sandbox Code Playgroud)
在执行中someMethod我遇到了崩溃:
@implementation Widget
- …Run Code Online (Sandbox Code Playgroud)