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 8022185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:11:45+00:00 2026-06-04T22:11:45+00:00

I have a facade singleton that I’d like to forward some class method calls

  • 0

I have a facade singleton that I’d like to forward some class method calls to some “static” class.

At first glance, forwardInvocation: appeared to be a possible solution, however, NSInvocation‘s invokeWithTarget: and setTarget: only accept an id, i. e. a pointer to an instance, not a class itself. I tried handing over [MyTargetClass class] as the target, but I still get a “No known class method […]” error when I call [Facade someForwardedMethod] somewhere. When I call [[Facade sharedInstance] someForwardedMethod] I get a “No visible @interface […] declares the selector […]” error.

Of course I am aware that I also need to override respondsToSelector: and methodSignatureForSelector:, so my code looks like this:

- (BOOL)respondsToSelector:(SEL)aSelector {
    if ([super respondsToSelector:aSelector]) {
        return YES;
    } else {
        return [MyTargetClass respondsToSelector:aSelector];
    }
}

- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
    NSMethodSignature* signature = [super methodSignatureForSelector:selector];
    if (!signature) {
        signature = [MyTargetClass methodSignatureForSelector:selector];
    }
    return signature;
}

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

    SEL aSelector = [anInvocation selector];

    if ([MyTargetClass respondsToSelector: aSelector]) {
        [anInvocation invokeWithTarget:[MyTargetClass class]];
    } else {
        [super forwardInvocation:anInvocation];
    }
}

Is there a way to make this work, or do I have to choose another approach?


EDIT: I have tried both ways that Rob Napier mentions in his answer, here are my findings:

I can call a class method in my target class through the facade instance with

[(id)[Facade sharedInstance] doSomethingClassyInTargetClass];

It’s a bit uglier than I hoped for, but it works. However, I can not call a class method in my target class when I address the facade class. To quieten the compiler I can write

[(Class)[Facade class] doSomethingClassyInTargetClass];

but then it throws an ‘NSInvalidArgumentException’ “[Facade doSomethingClassyInTargetClass]: unrecognized selector sent to class […]” at runtime. Apparently the class methods of the facade class get resolved without respect for forwardInvocation:, but after all it has a - in front…

  • 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-04T22:11:46+00:00Added an answer on June 4, 2026 at 10:11 pm

    Ah, when you added the “No visible @interface […] declares the selector […]”, it is all clear.

    Consider a simpler form with just instance methods. You implement -forwardInvocation:, and then you have code like this:

    [obj doSomething];
    

    Now, MyObject doesn’t actually claim doSomething in its header, even though it will respond to it. So the compiler complains that this probably won’t work. The fix for that is:

    [(id)obj doSomething];
    

    When you declare something id, the compiler stops checking whether the target actually implements the selector. But it’s also possible that no interface declares doSomething. Then the compiler is once again suspicious that it’s probably a typo, and gives you a warning. And by “no interface,” I mean “no interface that the compiler has access to.” The compiler only has access to interfaces in this compile unit (i.e. the .m file and the headers it includes). So you need to make sure you include the header that defines this selector.

    Now for classes, you can’t use id, but you should be able to use Class to achieve the same thing, such as:

    [(Class)MyClass doSomethingClassy];
    

    If may want to see the RNObserverManager sample code from iOS:PTL Chapter 4 which demonstrates something similar.

    You should also definitely look at forwardTargetForSelector: that Ken Thomases references.


    You don’t have to cast sharedInstance to id. Just change the signature, since you’ll always want to use it that way:

    + (id)sharedInstance;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a facade class that my controller class calls out to and in
In my service facade layer, I have a service class with a method/operation that
I have a mediator that I've registered for a navigation page: facade.registerMediator(new NavPageMediator(viewComponent)); I'm
I have an assembly which is being developed to create a facade around some
I have a Java web application that uses the SLF4J logging facade. To date,
I have 2 UIViewControllers in a UITabBar and would like to create a facade
I have a simple Android application that uses an instance of a class, let's
I have an application which has some classes that handle some specific functions, have
I have a Facade that has a persistence unit. And I need the Facade
I currently have a C function that I'd like to use in .NET (C#).

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.