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
I have NSMutableArray which contains NSObjects. Each NSObject contains a NSString as property which
Share
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:
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
-longLongValuemethod: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
-epochTimeValuemethod that extracts the time to NSString. That’d let you use code similar to what’s above.