Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8223395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:40:51+00:00 2026-06-07T14:40:51+00:00

I want to use message-forwarding on my SZNUnmanagedReference class. It has this properties: @property

  • 0

I want to use message-forwarding on my SZNUnmanagedReference class. It has this properties:

@property (nonatomic, strong) NSSet *authors;
@property (nonatomic, strong) SZNReferenceDescriptor *referenceDescriptor;

Basically, when an instance of UnmanagedReference receives the message authorsString, it should forward it to referenceDescriptor, which has a method named - (NSString *)authorsStringWithSet:(NSSet *)authors.

So, i wrote this in 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) isEqualToString:NSStringFromSelector(@selector(authorsString))] && [self.referenceDescriptor respondsToSelector:@selector(authorsStringWithSet:)]) {
        return YES;
    } else {
        return NO;
    }
}

- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
    NSMethodSignature *signature = [super methodSignatureForSelector:aSelector];
    if (!signature) {  
        signature = [self.referenceDescriptor methodSignatureForSelector:@selector(authorsStringWithSet:)];
    }
    return signature;
}

It all seems to work, the code in the SZNReferenceDescriptor class gets executed.
However, I don’t know how to get the authorsString back. If I understood the documentation correctly, I think the referenceDescriptor is supposed to send the result back to the original sender of the message. But it doesn’t seem to work. In my test class, [unmanagedReference authorsString] returns nil.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:40:53+00:00Added an answer on June 7, 2026 at 2:40 pm

    The problem is that you’re constructing a new NSInvocation object, whose return value isn’t accessible at the point where it’s needed (the “top” of the message dispatch “stack”). The runtime only knows about the one that it created for you (the argument to forwardInvocation:; that’s the one whose return value it will use. All you have to do, then, is to set its return value:

    - (void)forwardInvocation:(NSInvocation *)anInvocation {
    
        if (anInvocation.selector == @selector(authorsString)) {
            id retVal = [self.referenceDescriptor authorsStringWithSet:self.authors];
    
            [anInvocation setReturnValue:&retVal];   // ARC may require some memory-qualification casting here; I'm compiling this by brain at the moment
        } else {
            [super forwardInvocation:anInvocation];
        }
    }
    

    In fact, there’s actually no need to create that new invocation; since all you need is the return value of the method, you can just send the message directly (which you could also do if you just implemented authorsString on SZNUnmanagedReference, rather than using the forwarding mechanism).

    Also, note that there’s no need to convert selectors to and from strings in order to compare them — SELs can be compared directly using the equality operator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use my message bundle (messages_fr.properties) in a Java class with seam.
I want to use the error message returned by a RuleViolation as the validationMessage
I want to use XmCreate{Error|Warning|Info}Dialog to display some message in screen in my SDL
I want use this 1 for using Bar code or QR code scanner. I
I have this simple interface/class: public abstract class Message {} public class Message1 extends
Specifically, I want to use Point-to-point Message Queue but because I am still using
I want to use a custom icon in MessageBox.Show(Message, Title, MessageBoxButton.OK, MeesageBoxIcon.myIcon) Method. Any
I want to forward a message (such as WM_MOUSEWHEEL) when I'm over this control
I want to use WatiN to verify the error message in a JavaScript alert
I want to use my computer's IP address to send a message using socket

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.