以下代碼實現將方法轉發給NSNumber實例的NSProxy子類。-forwardInvocation與Clang-LLVM一起使用,但不與GCC一起使用
但是,當調用[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;
}
感謝您的解釋清楚的答案,我覺得這是與期待一個id指針返回作爲浮動浮標。剛剛沒有看到任何有關潛在缺陷的Apple文檔。 – rebo 2009-09-21 08:36:24