0

Say I have Stored some array of data using NSMutableArray. The stored array contains Timestamp and real time datas

I am receiving array of size 6 each time from a sensor device. The first position always has time stamp data and remaining position is occupied by real time datas. So, I have stored them sequentially in an NSMutableArray enter image description here

Here I am receiving datas with Time stamp in different order. So, I am in need to sort the time stamp in Ascending order with respect to datas (array of size 5) that are tied up with time stamp. So that I can able to plot the graph associated with each time stamp.

So my question is how to sort the time stamp without disturbing the data that are associated with each TimeStamp values.

2 Answers 2

2

you can use -sortedArrayUsingFunction:context:

eg.

NSArray * sortedArray = [otherArray sortedArrayUsingFunction: DataComparatorF context:nil];

NSInteger DataComparatorF (id a, id b, void *context)
{
   // return NSOrderedSame, NSOrderedAcending or NSOrderedDecending of a with respect to b
}
Sign up to request clarification or add additional context in comments.

Comments

0

I would suggest a different format for storing your data -- I would use an array of dictionaries with 2 keys, one for the timestamp, and one for the data (whose value would be an array of the 5 values). Then you can sort the array with sortedArrayUsingDescriptors:, using sortDescriptorWithKey:ascending: as the descriptor (and passing whatever key name you use for the timestamp). You don't say what form your timestamp is in. If it's a string, you'll probably have to convert it to an NSDate object first to sort it properly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.