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

  • Home
  • SEARCH
  • 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 7574931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:33:33+00:00 2026-05-30T16:33:33+00:00

I have NSMutableArray which contains NSObjects. Each NSObject contains a NSString as property which

  • 0

I have NSMutableArray which contains NSObjects. Each NSObject contains a NSString as property which has epoch time. Now i want to sort the array objects according to epoch time…please help me to achieve this…Thanks in advance

  • 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-30T16:33:34+00:00Added an answer on May 30, 2026 at 4:33 pm

    Sorting an array is easy. All you need is a piece of code that can compare two objects in the array. You can provide that code in the form of a method, function, or comparator block. So, let’s say you opt for the comparator:

    [myArray sortUsingComparator:^(NSString *string1, NSString *string2) {
            // your code goes here
        }];
    

    Replace the commented line with your code to get the times from each string and compare them. This is likely the part you’re really asking about. I can’t provide that code for you since I don’t know exactly what your strings look like. If the only thing in the string is the number of seconds since the epoch, then it’s as simple as calling NSString’s -longLongValue method:

    [myArray sortUsingComparator:^(NSString *string1, NSString *string2) {
            long long time1 = [string1 longLongValue];
            long long time2 = [string2 longLongValue];
            NSComparisonResult result = NSOrderedDescending;
            if (time1 < time2)
                result = NSOrderedAscending;
            else if (time1 == time2)
                result = NSOrderedSame;
            return result;
        }];
    

    If your strings contain other information, you may need to use some NSString methods or a NSScanner to extract the information you want. To keep your comparator block simple, you might want to use a category to add an -epochTimeValue method that extracts the time to NSString. That’d let you use code similar to what’s above.

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

Sidebar

Related Questions

I have a NSMutableArray which contains a few NSString objects. How can I test
I have an NSMutableArray instance which contains N number of objects and I want
I have a NSMutableArray walkArray which contains another array walkSteps. I want to create
I have an NSMutableArray called myObjectArray which contains and array of NSObjects called myObject.
I have class Item and class List (which has an NSMutableArray). Every time class
i have one problem when i sort the NSMutablearray using date and time wise.
I have a class (from NSObject ) that contains: NSString name int position float
I have some NSMutableArray in tableView which contain class Lesson @interface Lesson : NSObject
Please help me i have a NSMutableArray which contains data until viewDidLoad is finished.
I have a table of Checklists , each of which contains a bunch of

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.