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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:39:14+00:00 2026-05-26T05:39:14+00:00

Does Objective C have a function like Smalltalk’s Block valueWithArguments ? I’m looking for

  • 0

Does Objective C have a function like Smalltalk’s Block valueWithArguments?

I’m looking for a function with a signature like:

apply(^(), NSArray* args)

Alternatively, is there a way to call a selector over a list of arguments?

  • 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-26T05:39:15+00:00Added an answer on May 26, 2026 at 5:39 am

    With blocks you probably have to do some va_args magic. Calling a selector with variable arguments can be done but you probably want some helpers to make it a bit less painful.

    NSObject+performSelectorWithArgsArray.h

    @interface NSObject (performSelectorWithArgsArray)
    - (id)performSelector:(SEL)sel withArgsArray:(NSArray *)args;
    @end
    

    NSObject+performSelectorWithArgsArray.m

    @implementation NSObject (performSelectorWithArgsArray)
    - (id)performSelector:(SEL)sel withArgsArray:(NSArray *)args {
      NSInvocation *inv = [NSInvocation invocationWithMethodSignature:
                           [self methodSignatureForSelector:sel]];
      [inv setSelector:sel];
      [inv setTarget:self];
      for (int i = 0; i < args.count; i++) {
        id a = [args objectAtIndex:i];
        [inv setArgument:&a atIndex:2 + i]; // 0 is target, 1 is cmd-selector
      }
      [inv invoke];
    
      NSNumber *r;
      [inv getReturnValue:&r];
      return r;
    }
    @end
    

    And then use it like this:

    #import "NSObject+performSelectorWithArgs.h"
    
    @interface SomeClass : NSObject
    @end
    
    @implementation SomeClass
    - (NSNumber *)withA:(NSNumber *)a withB:(NSNumber *)b {
      return [NSNumber numberWithInt:a.intValue + b.intValue];
    }
    @end
    
    - (void)someMethod {
      SomeClass *a = [[SomeClass alloc] init];
      SEL sel = @selector(withA:withB:);
      NSArray *args = [NSArray arrayWithObjects:
                       [NSNumber numberWithInt:2],
                       [NSNumber numberWithInt:3],
                       nil];
      NSNumber *r = [a performSelector:sel withArgsArray:args];
      NSLog(@"%d", r.intValue);
    }
    

    If you choose to do something like this I recommend that you really read up on how NSInvocation works as it can bite quite hard. Not sure if it is possible to do this without requiring that all arguments and return value are objects.

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

Sidebar

Related Questions

I have an NSArray of Foos in an Objective-C program. I would like to
Does anyone use have a good regex library that they like to use? Most
On OS X, does Objective-C compile to native code or byte-code? Can Objective-C programs
Does Google force employees who have offers from Facebook to leave immediately?
Does the Java language have delegate features, similar to how C# has support for
Does anyone have any recommendations of tools that can be of assistance with moving
Does C# have built-in support for parsing strings of page numbers? By page numbers,
I have a sumranges() function, which sums all the ranges of consecutive numbers found
In Objective-C, I have a category for a class: @interface UILabel(CustomInit) - (id)initWithCoder:(NSCoder *)coder;
First of all i have to do this without IB and without advanced Objective-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.