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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:06:22+00:00 2026-05-30T02:06:22+00:00

I have been knocking my head against the wall trying to figure whether it

  • 0

I have been knocking my head against the wall trying to figure whether it is possible to call a function defined in a different class. Unfortunately, my limited knowledge in Objective C prevented me to reach a satisfactory answer. Basically, I have one class called Caller and a different class called Functions that I would like to hook to at run time. Class Functions will have all the functions defined that caller is going to reference to at run time.
This is the code in its entirety:

--- Caller.h -------------------
#import "Functions.h"
@interface Caller
{
  int callerId;
  NSMethodSignature *sig;
  NSInvocation *func;
}
@property(retain) NSInvocation* func;
@end

--- Caller.m -------------------
#import "Caller.h"
@implementation Caller
@Synthesize func;
-(id)initWithFunction: (SEL)f
{
  if (self)
   {  Sig = [Caller instanceMethodSignatureForSelector: f];
      func= [NSInvocation invocationWithMethodSignature: Sig];}
   return self;
}
@end

--- Functions.h -------------------
@interface Functions
-(int)SayHello;
@end

--- Functions.m -------------------
#import "Functions.h"
@implementation
-(int)SayHello
{
   NSLog(@"Hello");
   return 0;
}

---------main.m-----------------
#import <Foundation/Foundation.h>
#import "Caller.h"
#import "Functions.h"
int main
{
   NSAutoreleasePool *  pool [[NSAutoreleasePool alloc]init];
   Functions* ftn = [[Functions alloc]init];
   Caller * c = [[Caller alloc]initWithFunction: @selection(SayHello)];
   [c.func setTarget:c];
   [c.func invoke];
   [pool drain];
    return 0;
}

The code was compiling fine but at run time, it encountered an error because instanceMethodSignatureForSelector is 0. If I make Caller class inherit from Functions class, then the program will work like a charm. But Functions class in my case has to be independent from Caller class. Is there a work around?

  • 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-05-30T02:06:23+00:00Added an answer on May 30, 2026 at 2:06 am

    +instanceMethodSignatureForSelector: returns nil because Caller doesn’t have such a method – it is implemented in another class which you can’t know with the given data at that point.

    Instead you can retrieve the method signature from the target later, e.g.:

    @implementation Caller
    // ...
    - (void)invokeWithTarget:(id)target {
        NSMethodSignature *sig = [target methodSignatureForSelector:sel_];
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been knocking my head against a problem for ages until I realised what
I've been knocking my head against this for some time now. I'm not really
I have been knocking my head of for almost half a day, but still
Have been trying to encrypt an xml file to a string so that I
Have have been trying to make a validator for my xml files. I have
Have been trying to fix this problem I have here. Basically I have a
Have been trying the whole day long and googled the **** out of the
have been trying couple of hours now to make my iphone app universal. The
Have been pulling out my hair trying to find out why my sessions are
Have been pulled down into the realm of CORBA... I am trying to quickly

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.