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

  • Home
  • SEARCH
  • 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 7921091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:27:26+00:00 2026-06-03T16:27:26+00:00

So basically I’m implementing the typical way to handle JavaScript calls in objc using

  • 0

So basically I’m implementing the typical way to handle JavaScript calls in objc using window.location=”myobj:mymethod:myarg:myotherarg”, however, I’m wondering if there is a way to apply an array of arguments to a method, similar to how you can in JavaScript.

Typically I’ve been doing

-(void) mymethod:(NSArray*) arr{
    //method knows how many arguments it takes and what they mean at each index
}

I’d prefer to do:

-(void) mymethod:(NSString*) myarg myOtherArg: (NSString*) myotherarg{
    //do stuff
}

and have a method like this:

+(void) callMethod:(NSString*)selectorName withArgs: (NSArray*)args onObject:(id) obj{
    //implementation
}
[JEHelpers callMethod:selector withArgs:someArrayOfArgs onObject:myapp]

is this possible?

  • 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-03T16:27:29+00:00Added an answer on June 3, 2026 at 4:27 pm

    If you know that no method will take more than two arguments, you could use performSelector:withObject:withObject: to do these calls. If the method takes less than two arguments, the unused withObject: fields will be ignored.

    + (id)callMethod:(NSString *)selectorName withArgs:(NSArray *)args onObject:(id)obj {
        id arg1 = nil, arg2 = nil;
        if([args count]) {
            arg1 = [args objectAtIndex:0];
            if([args count] > 1])
               arg2 = [args objectAtIndex:1];
        }
        return [obj performSelector:NSSelectorFromString(selectorName)
                         withObject:arg1 withObject:arg2];
    }
    

    If there could be more than two arguments, you will have to use NSInvocation. This class lets you construct a message by passing the various arguments and defining the selector and object, then send the message and get the result.

    + (id)callMethod:(NSString *)selectorName withArgs:(NSArray *)args onObject:(id)obj {
        SEL sel = NSSelectorFromString(selectorName);
        NSMethodSignature *signature = [obj methodSignatureForSelector:sel];
        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
        [invocation setSelector:sel];
        [invocation setTarget:obj];
        NSUInteger index = 2;
        for(id arg in args) {
            [invocation setArgument:&arg atIndex:index];
            ++index;
        }
        id result;
        [invocation setReturnValue:&result];
        [invocation invoke];
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I want to get a handle of the python interpreter so I can
Basically when user resizes my application's window I want application to be same size
Basically, I'm using python to print out some information in the terminal and some
Basically what I want to do it this: a pdb file contains a location
Basically I want to know how to set center alignment for a cell using
Basically, I'm optimizing a website for the different versions of IE. I'm using IE9
Basically I am writing a simple program using the boost socket library... I have
Basically I need to open a login window in a popup, so that it
Basically I have a gridview that is using a list as it's datasource. How
Basically I have some variables that I don't want to preinitialize: originalTime = None

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.