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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:53:18+00:00 2026-06-06T02:53:18+00:00

Stuck on KVCs in Obj-C again. I am wanting to use KVC to find

  • 0

Stuck on KVCs in Obj-C again.

I am wanting to use KVC to find the minimum value across multiple keys.

Consider the following array:

NSArray *data = [[NSArray alloc] initWithObjects:
                 [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:2.0], @"a", [NSNumber numberWithFloat:5.0], @"b", [NSNumber numberWithFloat:4.0], @"c", nil],
                 [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:3.0], @"a", [NSNumber numberWithFloat:1.0], @"b", [NSNumber numberWithFloat:1.5], @"c", nil],
                 [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:9.0], @"a", [NSNumber numberWithFloat:7.0], @"b", [NSNumber numberWithFloat:6.0], @"c", nil],
                 nil];

I can find the minimum value for ‘a’, ‘b’, or ‘c’ easily with:

float minKeyA = [[data valueForKeyPath:@"@min.a"] floatValue];  // value: 2.0
float minKeyB = [[data valueForKeyPath:@"@min.b"] floatValue];  // value: 1.0
float minKeyC = [[data valueForKeyPath:@"@min.c"] floatValue];  // value: 1.5

What I am wanting to achieve is to take a NSSet or NSArray of keys and find the minimum value across the pool of those keys.

NSSet *keySet1 = [NSSet setWithObjects:@"a", @"b", nil]; 
// use to find absolute minimum value across keys 'a' and 'b' --> desired value 1.0
NSSet *keySet2 = [NSSet setWithObjects:@"a", @"c", nil];
// use to find absolute minimum value across keys 'a' and 'c' --> desired value 1.5
NSSet *keySet3 = [NSSet setWithObjects:@"a", @"b", @"c", nil];
// use to find absolute minimum value across keys 'a', 'b', and 'c' --> desired value 1.0

Appreciate any pointers 🙂

  • 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-06T02:53:19+00:00Added an answer on June 6, 2026 at 2:53 am

    A naive solution would be to first find the minimum value for each key and then find the minimum among those minimum values in a second step.

    NSMutableSet *localMinima = [NSMutableSet setWithCapacity:[keySet1 count]];
    for (NSString *key in keySet1) {
        NSString *keyPath = [NSString stringWithFormat:@"@min.%@", key];
        NSNumber *localMin = [data valueForKeyPath:keyPath];
        [localMinima addObject:localMin];
    }
    NSNumber *globalMin = [localMinima valueForKeyPath:@"@min.self"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Stuck again. :( I have the following code crammed into a procedure invoked when
just stuck with strange thing. I have the following code: -(void)ImageDownloadCompleat { [self performSelectorOnMainThread:@selector(updateImageButton:)
Stuck with this weird question Why following code is OK for g++ #include <QObject>
I stuck with following constellation: JSBIN Example I want a click function for Check
Little stuck, i need to use Request.IsLocal inside a class library, not the web
I stuck in a situation where I want to find which tables I've created
got stuck on this part of my program.. and it seems i cant find
Kinda stuck on this one. I have a table with name/value columns: NameValue table
I stuck in a situation. I am using JS Helper. I used the following
Stuck a bit with the following and would love some ideas/pointers in the right

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.