我正在与NSInvocation
一起工作,需要从中检索其中一个属性。为什么缓冲区需要在NSInvocation上__unsafe_unretained - getArgument:atIndex:?
我用下面的代码,但我有一些怪异的行为叫[invocation invoke];
:
NSString *propertyName = nil;
[invocation getArgument:&propertyName atIndex:3];
我看,为了使ARC下工作,我们需要使用__unsafe_unretained
:
__unsafe_unretained NSString *propertyName = nil;
[invocation getArgument:&propertyName atIndex:3];
它的工作,很好!但我想明白为什么。任何人都可以解释吗?
这是一个dup或理解答案的好地方:http://stackoverflow.com/questions/8672675/why-does-the-arc-migrator-say-that-nsinvocations-setargument-is-没有安全,unle。关键是调用不保留参数。通过将其定义为不安全,您承认自己明白这一点,并且您将采取措施确保参数的生命周期> =调用 – danh