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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:56:37+00:00 2026-05-15T08:56:37+00:00

For learning (not practical — yet) purposes, I’d like to use the following method

  • 0

For learning (not practical — yet) purposes, I’d like to use the following method on an NSDictionary to give me back a set of keys that have values using a test I’ve defined. Unfortunately have no idea how to specify the predicate.

NSDictionary keysOfEntriesPassingTest:
- (NSSet *)keysOfEntriesPassingTest:(BOOL (^)(id key, id obj, BOOL *stop))predicate

Let’s say for example all my values are NSURLs, and I’d like to get back all the URLs that are on port 8080. Here’s my stab at coding that — though it doesn’t really make sense to me that it’d be correct:

NSSet * mySet = [myDict keysOfEntriesPassingTest:^(id key, id obj, BOOL *stop) {
                 if( [[obj port] isEqual: [NSNumber numberWithInt: 8080]]) {
                     return key;
                 }]

And that’s because I get back the following compiler error:

incompatible block pointer types initializing ‘void (^)(struct objc_object *, struct objc_object *, BOOL *)’, expected ‘BOOL (^)(struct objc_object *, struct objc_object *, BOOL *)’

What am I missing? I’d appreciate a pointer at some docs that go into more detail about the “Block object” that the predicate is supposed to be.

Thanks!


And this is the code that works:

NSSet *mySet = [myDict keysOfEntriesPassingTest:^(id key, id obj, BOOL *stop)
{
  if ([[obj port] isEqual:[NSNumber numberWithInt: 8080]])
     return YES;
   else
     return NO;
}];
  • 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-15T08:56:38+00:00Added an answer on May 15, 2026 at 8:56 am

    The error indicates that your block must return a BOOL, rather than id. Check the docs. I suspect you are expected to return YES if the key/obj pair passes the desired test.

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

Sidebar

Related Questions

I am not very good with Regex but I am learning. I would like
I am learning to use the Dvorak keyboad layout, but I am not good
I am learning linux programming and want to do the following. I would like
I'm learning Grails/GORM and as I've understood it the current best practice is not
I'm not a math guy in the least but I'm interested in learning about
I'm interested in learning Haskell on my own time (not through a course), but
I'm just learning about SVG, and it seems great but I'm not sure about
I'm learning XML, currently of Wikibooks, but that is kinda huge and not oversee-able...
I am a C# developer. Still learning. I had not learn all the features
I am looking at doing a small web application for learning purposes, using .NET.

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.