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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:28:09+00:00 2026-05-26T08:28:09+00:00

I created a veriadic Category method on NSArray to filter it into a dictionary

  • 0

I created a veriadic Category method on NSArray to filter it into a dictionary with given blocks and keys

typedef BOOL (^TestBlock)(id element);
- (NSDictionary *)dictionaryByFilteringWithBlocksAndKeys:(TestBlock)firstBlock, id firstKey,... NS_REQUIRES_NIL_TERMINATION;

Usage:

NSArray *array = [NSArray arrayWithObjects:@"a", @"aa", @"ab", @"cc", @"cd", @"dd", nil];
NSDictionary *dict = [array dictionaryByFilteringWithBlocksAndKeys:
                                    ^BOOL(id element) {return [element hasPrefix:@"a"];},@"a",
                                    ^BOOL(id element) {return [element hasPrefix:@"c"];},@"c", 
         nil];

It works quite good, but I wonder, how I can check, if a given block (other then the first) has the typedef’ed signature.

I get the blocks from the va_list with TestBlock block = va_arg(args, TestBlock);, but it also eats non-sense blocks like

NSDictionary *dict = [array dictionaryByFilteringWithBlocksAndKeys:
                                    ^BOOL(id element) {return [element hasPrefix:@"a"];}, @"a", 
                                    ^(id element) {;}, @"c", 
                          nil];

without complaining.

Is there a way to check, if a block has the same signature as a typedef at runtime?

  • 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-26T08:28:09+00:00Added an answer on May 26, 2026 at 8:28 am

    No, there is no way to check. This would require new syntax in the compiler. Effectively, you want “these arguments are optional/variadic, but must follow this type pattern”.

    Also note that treating a specifically typed argument list as a va_list is not technically correct, either. It will mostly work by coincidence on most ABIs, but not all. (Not that you are doing that, but it often comes up in these contexts).

    can you give me an example of what you mean with specially typed
    argument list?

    Sure, consider:

    id objc_msgSend(id,SEL,...);
    

    That is a var-args argument list. Now, you might think you can do this:

    objc_msgSend(mutableArray, @selector(addObject:), anObject);
    

    But, technically, you can’t. varargs are not compatible with specifically typed argument lists, by the C spec. Thus, you need to typecast:

    void (*func)(id,SEL,id) = (void*)objc_msgSend;
    func(mutableArray, @selector(addObject:), anObject);
    

    That is, if the called API is not also varargs, then the call site must be compiled against a declaration of the call that has full argument type info…

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

Sidebar

Related Questions

i created a WCF service that also writes into a log file. i put
I created a class and overridden the equals() method. When I use assertTrue(obj1.equals(obj2)) ,
Created a views.py method to get the data posted from an html form. As
Created .NET WCF service, tested it - works. Generated schemas from Data and service
I created a program using dev-cpp and wxwidgets which solves a puzzle. The user
I created a few mediawiki custom tags, using the guide found here http://www.mediawiki.org/wiki/Manual:Tag_extensions I
I created a single page (with code behind .vb) and created Public intFileID As
I created an Interop user control in VS2005. When the user control is shown
I created a simple .NET windows application in Visual Studio 2005 and on just
I created a Rails application normally. Then created the scaffold for an event class.

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.