【发布时间】:2011-12-13 14:50:13
【问题描述】:
如何更改以下代码以与 ARC 兼容:
MyObj* fn = nil;
[self performSelectorOnMainThread:@selector(popSomething:) withObject:(id)&fn waitUntilDone:YES];
现在,我收到以下错误:
error: cast of an indirect pointer to an Objective-C pointer to '__strong id' is disallowed with ARC [4]
【问题讨论】:
-
你为什么不能用
[self performSelectorOnMainThread:@selector(queuedFileNamesPop:) withObject:fn waitUntilDone:YES];来代替? -
@AndreyZ:因为那样,在这个调用返回之后,
fn仍然是nil。 -
@Albert:那是因为 fn 最初是
nil。 -
@MusiGenesis:是的,通过传递
&fn,被调用的函数实际上可以覆盖它(这就是我想要的)。
标签: objective-c automatic-ref-counting