objective c - NSArray filter using NSPredicate, comparing dates -


i have person entity attribute date_of_birth declared nsstring. if have array of 'person' instances , need filter them down date_of_birth less 25/11/2005 using predicate format when nslogged is:

function(date_of_birth, "yyyy_mm_dd_dateformat") <[cd] cast(154575908.000000, "nsdate") 

where yyyy_mm_dd_dateformat() category method on nsstring returns string instance date.

i not getting expected results. doing wrong, , bit says cast(154575908.000000, "nsdate" , valid?

update: changing date_of_birth attribute type nsdate not option @ moment due size, maturity , complexity of project.

dates best represented nsdate, implements inequality via earlierdate: , laterdate: methods. these answer earlier/later date between receiver , parameter.

your conversion method looks ...

// return nsdate string given in dd/mm/yyyy - (nsdate *)datefromstring:(nsstring *)string {     nsdateformatter *formatter = [[nsdateformatter alloc] init];     [formatter setdateformat:@"dd/mm/yyyy"];     return [formatter datefromstring:string]; } 

the array can filtered block-based nspredicate uses nsdate comparison...

nsdate *november25 = [self datefromstring:@"25/11/2005"]; nspredicate *predicate = [nspredicate predicatewithblock:^bool(person *person, nsdictionary *bind){     // important part, lets things in nsdate form can use them.     // of course quicker alter data type, can covert on fly     nsdate *dob = [self datefromstring:person.date_of_birth];     return date_of_birth == [november25 earlierdate:dob]; }];  // assumes allpeople nsarray of person objects filtered // , assumes person has nsstring date_of_birth property nsarray *oldpeople = [allpeople filteredarrayusingpredicate:predicate]; 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -