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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:48:27+00:00 2026-06-10T06:48:27+00:00

This example is contrived, but it shows my point. So, if I have an

  • 0

This example is contrived, but it shows my point.

So, if I have an object graph like the following:

{
sex = male;
uid = 637650940;
work = ({
    employer = {
        id = 116420715044499;
        name = "Software Engineer";
    };
    "end_date" = "0000-00";
    "start_date" = "0000-00";
}, {
    employer = {
        id = 188733137832278;
        name = "Apple";
    };
});
},
//Some more objects

(This is an NSArray containing NSDictionarys that have an object of type NSArray).

The key field is work. I want a Key Path that will take the first object in the work array.

If I do this:

NSArray* work = [outerArrayObject objectForKey: @"work"];
id name = [work valueForKeyPath: @"employer.name"];

I get an array containing each name (In the above case, Software Engineer & Apple). Is there a collection operator or something to return the first object? Bonus points if you can develop a Key Path to sort each work by start_date also 🙂

  • 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-10T06:48:29+00:00Added an answer on June 10, 2026 at 6:48 am

    Well to answer my own question, one way to do it is this:

    1) Define the following category

    @implementation NSArray (CustomKVOOperators)
    
    - (id) _firstForKeyPath: (NSString*) keyPath {
        NSArray* array = [self valueForKeyPath: keyPath];
        if( [array respondsToSelector: @selector(objectAtIndex:)] &&
            [array respondsToSelector: @selector(count)]) {
            if( [array count] )
                return [array objectAtIndex: 0];
            else
                return nil;
        }
        else {
            return nil;
        }
    }
    
    @end
    

    2) Use this KeyPath syntax

    NSArray* work = [outerArrayObject objectForKey: @"work"];
    id name = [work valueForKeyPath: @"@first.employer.name"];
    

    Thanks to this clever person.

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

Sidebar

Related Questions

This is a contrived example, but it illustrates my problem much more concisely then
This example shows what I am trying to do: http://jsfiddle.net/Dqjvy/ I would like it
This is a somewhat contrived example meant to show a point. Here are two
Consider this contrived, trivial example: var foo = new byte[] {246, 127}; var bar
This example is simplified a bit, but in my ASP.NET web page in my
Let's say I have a list that looks like this: <ul> <li id=q></li> <li
I have two models that are related to each other. For a contrived example,
I am wondering why the following contrived example code works perfectly fine in Visual
I have class like this class variable { public: variable(int _type=0) : type(_type), value(NULL),
I have a bit of code like this in my template: #{list people, as:'person'}

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.