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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:38:52+00:00 2026-06-14T15:38:52+00:00

I am confused in one of the sorting & merging problem. Let me describe

  • 0

I am confused in one of the sorting & merging problem. Let me describe my problem as follows.

Step 1. I have an array. I am just writing the console log of an array to understand the structure of it.

(
    {
        id_ = 1,
        name_ = "some xyz name",
        date_ = "2012/01/24 05:25:30 AM"
    },
    {
        id_ = 2,
        name_ = "some ABC name",
        date_ = "2012/01/25 06:25:30 AM"
    },
    {
        id_ = 1,
        name_ = "some PQR name",
        date_ = "2012/01/22 04:30:30 AM"
    },
)

Step 2. So, To sort above array, I have placed following code.

NSArray *myArray = // someHow I get those values listed above.
NSSortDescriptor *sortD1=[[NSSortDescriptor alloc] initWithKey:@"date_" ascending:YES];
myArray = [myArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortD1]];

Step 3. Now I have complete set of sorted array.

Step 4. I have similar kind of another array.

(
    {
        obj_id_ = 11,
        obj_date_ = "2012/01/24 05:25:30 AM"
    },
    {
        obj_id_ = 21,
        obj_date_ = "2012/01/23 05:25:30 AM"
    },
    {
        obj_id_ = 17,
        obj_date_ = "2012/01/21 05:25:30 AM"
    },
)

Step 5. So, To sort above array, I have placed following code.

NSArray *myArray2 = // someHow I get those values listed above.
NSSortDescriptor *sortD2=[[NSSortDescriptor alloc] initWithKey:@"obj_date_" ascending:YES];
myArray2 = [myArray2 sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortD2]];

Step 6. Now I have to merge both arrays but It should be sorted based on the date.

(
    {
        obj_id_ = 17,
        obj_date_ = "2012/01/21 05:25:30 AM"
    },
    {
        id_ = 1,
        name_ = "some PQR name",
        date_ = "2012/01/22 04:30:30 AM"
    },
    {
        obj_id_ = 21,
        obj_date_ = "2012/01/23 05:25:30 AM"
    },
    {
        id_ = 1,
        name_ = "some xyz name",
        date_ = "2012/01/24 05:25:30 AM"
    },
    {
        obj_id_ = 11,
        obj_date_ = "2012/01/24 05:25:30 AM"
    },
    {
        id_ = 2,
        name_ = "some ABC name",
        date_ = "2012/01/25 06:25:30 AM"
    }
)

Expected output, I want to have is as above. Just that I don’t know the logic to merge two different arrays having different key-values. I am trying to build a logic for this but It returns an empty array & its wrong. So, I am not posting it here.

Note : If this question is duplicate, before down-voting it, inform me through comments. I will remove it & will be thankful for needful links & support. 🙂

  • 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-14T15:38:53+00:00Added an answer on June 14, 2026 at 3:38 pm

    First I would define a function that returns a date depending on the object that it is passed:

    - (NSDate *)dateForObject:(id obj) {
        if ([obj class] == [MyClass1 class]) {
            return ((MyClass1) obj).date_;
        }
        else {
            return ((MyClass2) obj).obj_date_;
        } 
    }
    

    Then I would sort using blocks:

    NSArray *sortedArray;
    sortedArray = [mergedArray sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
        NSDate *aDate = [self dateForObject:a];
        NSDate *bDate = [self dateForObject:b];        
        return [aDate compare:bDate];
    }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm quite new to MySQL and I'm confused with one problem: I have one
I'm a bit confused with one thing, look: Let's say we have source tree
Totally confused by this one... We have a WAMPServer installation set up, running a
I'm sometimes confused to using which one of them, say I have a function
I have a one-to-many like array. Structure example: [ [ InvoiceID, [ InvoiceEntry1_label, InvoiceEntry2_label
Kind of confused by one part of my HW problem. It seems like it
Bit confused with this one. Basically, I have a column in a table, and
Ok so i am just learning recursion and i am confused on one point.
I am confused on one simple situation is that when I have already created
I just found that I am confused about one basic question in C++ 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.