Q:

NSPredicate get item with name and condition

I have NSArray of custom objects.  Custom object has properties like: name, timestamp, title and so on ... In this array there are multiple objects with same name but with different time stamps.  I need to get for each name the most recent record.  I would like to use NSPredicate, but I don't know how to combine search for name with comparison of time stamps... 

A:

First of all you need to filter all the same names using:
NSArray *arrName1 = [NSArray ]

NSArray *arrData; //This array contains main data
NSString *strName1 = @"Amit"; //Taken Amit name for sample

//This will give you array with same name
NSArray *arrName1 = [arrData filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@" name == %@",strName1]];

//Now you can sort this array using NSSortDescriptor based on timestamp
NSSortDescriptor * sortByTimeStamp = [NSSortDescriptor sortDescriptorWithKey:@"timestamp" ascending:NO];
[scores sortUsingDescriptors:[NSArray arrayWithObject:sortByTimeStamp]];

This will give you array in descending order of the timestamp in arrName1.  Now you need to use it to apply in the main array. 
Hope this will help you.  Happy coding :)

