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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:34:18+00:00 2026-05-29T04:34:18+00:00

I had a result that i wanted (getting max value.) with using keypath feature

  • 0

I had a result that i wanted (getting max value.) with using keypath feature by someone’s help.

The code : getting a max value

NSNumber *number1 = [[NSNumber alloc]initWithInt:10];
NSNumber *number2 = [[NSNumber alloc]initWithInt:20];
NSNumber *number3 = [[NSNumber alloc]initWithInt:30];
NSMutableArray *array = [[NSMutableArray alloc]initWithObjects:number1, number2, number3, nil];
NSNumber *result = [array valueForKeyPath:@"@min.intValue"];

I wonder about various usage of keypath.

Below are questions.

Q1) How to get an instance of having a max value of int_test property?

Q2) How to get a max value of int_test property in Just instances?

Just *test1 = [[Just alloc]init];
test1.int_test = 10;

Just *test2 = [[Just alloc]init];
test2.int_test = 20;

Just *test3 = [[Just alloc]init];
test3.int_test = 30;

NSMutableArray *array = [[NSMutableArray alloc]initWithObjects:test1, test2, test3, nil];

NSLog(@"%@",[array valueForKeyPath:@"?????"]); <= Q1)
NSLog(@"%d",[array valueForKeyPath:@"?????"]); <= Q2)
  • 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-29T04:34:23+00:00Added an answer on May 29, 2026 at 4:34 am

    Note: Untested code ahead. Ideally, I’d test this before posting as an answer, but I don’t have time to do that just now. I believe the code is correct conceptually, but you may need to tweak it to get it to work. If you find any errors, please let me know so that I can make the necessary corrections.

    Q2) How to get a max value of int_test property in Just instances?

    Use this:

    int max = [array valueForKeyPath:@"@max.int_value"].intValue;
    

    Q1) How to get an instance of having a max value of int_test property?

    Use the NSArray method -indexOfObjectPassingTest: like this:

    int max = [array valueForKeyPath:@"@max.int_value"].intValue;
    BOOL (^MaxTest)(id, NSUInteger, BOOL) = ^(id obj, NSUInteger idx, BOOL *stop) {
        BOOL isMax = NO;
        if (obj.int_test == max) {
            isMax = YES;
            *stop = YES;
        }
        return isMax;
    }
    NSUInteger testMaxIndex = [array indexOfObjectPassingTest:MaxTest];
    Just testMax = [array objectAtIndex:testMaxIndex];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I originally had this code which I mistakenly thought would do what I wanted
I'm using pyDes to encrypt some data. I wanted to demonstrate that if you
I had posted this earlier on Stack Overflow, but couldn't get a positive result.
I had experience on Java, because of some results, I need to code in
Has anybody had any success getting Team Build to show xUnit.net test results and
Had a page that was working fine. Only change I made was to add
Had a good search here but can't see anything that gets my mind in
This question came about as a result of some mixed-language programming. I had a
I had an interview question that asked me for my 'feedback' on a piece
I was trying to make a constructor function and within it, i had/wanted to

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.