小编Cam*_*der的帖子

forwardInvocation:返回值丢失

我想在我的SZNUnmanagedReference类上使用消息转发.它有这个属性:

@property (nonatomic, strong) NSSet *authors;
@property (nonatomic, strong) SZNReferenceDescriptor *referenceDescriptor;
Run Code Online (Sandbox Code Playgroud)

基本上,当UnmanagedReference的实例收到消息时authorsString,它应该转发给它referenceDescriptor,它有一个名为的方法- (NSString *)authorsStringWithSet:(NSSet *)authors.

所以,我写道SZNUnmanagedReference.m:

- (void)forwardInvocation:(NSInvocation *)anInvocation {

    SEL aSelector = anInvocation.selector;

    if ([NSStringFromSelector(aSelector) isEqualToString:NSStringFromSelector(@selector(authorsString))]) {
        NSMethodSignature *signature = [self.referenceDescriptor methodSignatureForSelector:@selector(authorsStringWithSet:)];
        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
        NSSet *authors = [NSSet setWithSet:self.authors];
        [invocation setSelector:@selector(authorsStringWithSet:)];
        [invocation setArgument:&authors atIndex:2];
        [invocation setTarget:self.referenceDescriptor];

        [invocation invoke];
    } else {
        [self doesNotRecognizeSelector:aSelector];
    }
}

- (BOOL)respondsToSelector:(SEL)aSelector {
    if ([super respondsToSelector:aSelector]) {
        return YES;
    } else if ([NSStringFromSelector(aSelector) …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch objective-c message-forwarding ios

5
推荐指数
1
解决办法
790
查看次数