Ich habe Probleme, vorwärts zu kommen, um zu arbeiten. Aus irgendeinem Grund ignoriert die Objective-C-Laufzeit vollständig meine forwardInvocation: -Methode und löst eine nicht erkannte Selektorausnahme aus.forwardInvocation wird nicht aufgerufen?
Mein Testcode ist wie folgt:
@interface InvocationTest : NSObject
{
}
+ (void) runTest;
@end
@interface FullClass: NSObject
{
int value;
}
@property(readwrite,assign) int value;
@end
@implementation FullClass
@synthesize value;
@end
@interface SparseClass: NSObject
{
}
@end
@implementation SparseClass
- (void)forwardInvocation:(NSInvocation *)forwardedInvocation
{
NSLog(@"ForawrdInvocation called");
FullClass* proxy = [[[FullClass alloc] init] autorelease];
proxy.value = 42;
[forwardedInvocation invokeWithTarget:proxy];
}
@end
@implementation InvocationTest
+ (void) runTest
{
SparseClass* sparse = [[[SparseClass alloc] init] autorelease];
NSLog(@"Value = %d", [sparse value]);
}
@end
Ich arbeite Informationen aus den folgenden Quellen aus:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtForwarding.html#//apple_ref/doc/uid/TP40008048-CH105 http://cocoawithlove.com/2008/03/construct-nsinvocation-for-any-message.html
Soweit ich sagen kann, ist die Laufzeit sollte Aufruf forwardInvocation: auf der Instanz von SparseClass, wenn ich [Sparse-Wert] aufrufen, aber es wird vollständig ignoriert:
- [SparseClass Wert]: unerkannte Selektor Instanz gesendet 0x4b1c4a0 *** app Abschluss aufgrund abgefangene Ausnahme 'NSInvalidArgumentException', Grund: '- [SparseClass Wert]: unerkannte Selektor Beispiel 0x4b1c4a0 gesendet'
Super! Lief wie am Schnürchen. – Karl