下面的代码实现了一个 NSProxy 子类,它将方法转发到一个 NSNumber 实例。
但是,当调用 [nsproxy floatValue] 时,我在 GCC 4.2 下得到 0.0。
在 LLVM-Clang 下,我得到正确答案 42.0。
知道发生了什么吗?
(顺便说一下,这是在垃圾收集下运行的)
-(id) init;
{
_result = [NSNumber numberWithFloat:42.0];
return self;
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
{
return [[_result class] instanceMethodSignatureForSelector:aSelector];
}
- (void)forwardInvocation:(NSInvocation *)anInvocation
{
[anInvocation setTarget:_result];
[anInvocation invoke];
return;
}