-1

I have a NSMutableArraylike this.

[
 {
  "Employee": {
  "EmployeeCode": 17125,
  "DisplayName": "MI0000026 - ABC",
  "DisplayName2": "ABC2",
  "Initials": "W. S. S.",
  "Surname": "CCC",
  "FirstName": "ABC",
  "MiddleName": "CDE",
  "LastName": "",
  "FullName": "ABC EMPLOYEE",

},
"LeaveDetail": {
  "LeaveDetailId": 21,
  "LeaveEntryCode": 16,
  "RequestId": 20,
  "EmployeeCode": 17125,
  "LeaveYear": 2016,
  "LeaveTypeCode": 1,
  "BaseType": "ess",
  "LeaveDate": "2016-09-05T00:00:00",
}
}
]

there are several objects in this array which has these kind of dictionaries. I want to find all the objects in this array which has "LeaveDate": "2016-09-05T00:00:00" this LeaveDate key is inside the LeaveDetail dictionary. How can I find all the objects which has LeaveDate as "2016-09-05T00:00:00"

EDIT NSPredicate *predicate=[NSPredicate predicateWithFormat:@"LeaveDate CONTAINS[cd] %@",dm.strClickedDate];

But, I don't get any result.

Please help me. Thanks

Janmenjaya
  • 4,149
  • 1
  • 23
  • 43
Irrd
  • 325
  • 1
  • 6
  • 18
  • Possible duplicate of [Retrieve NSDictionary from NSArray where dictionary key has value X](http://stackoverflow.com/questions/15831183/retrieve-nsdictionary-from-nsarray-where-dictionary-key-has-value-x) – Droppy Oct 04 '16 at 06:07
  • Please search before posting. – Droppy Oct 04 '16 at 06:07
  • It's not the same,, mine has 2 types of objects,, and I have already tried this like this. NSPredicate *predicate=[NSPredicate predicateWithFormat:@"LeaveDate CONTAINS[cd] %@",dm.strClickedDate]; butI dont get any result.Thats why I posted this – Irrd Oct 04 '16 at 06:12
  • You should have added that to your question. We don't magically know what you have and haven't tried if you don't tell us. Also use the correct data type, which for that entry is `NSDate`, not `NSString`. – Droppy Oct 04 '16 at 06:13

1 Answers1

0
NSDictonary *dict = [yourMutableArray[0]];//get dict in array with index = 0
NSLog(@"%@",dict);
//*Log dict will show:
 {
  "Employee": {
  "EmployeeCode": 17125,
  "DisplayName": "MI0000026 - ABC",
  "DisplayName2": "ABC2",
  "Initials": "W. S. S.",
  "Surname": "CCC",
  "FirstName": "ABC",
  "MiddleName": "CDE",
  "LastName": "",
  "FullName": "ABC EMPLOYEE",

},
"LeaveDetail": {
  "LeaveDetailId": 21,
  "LeaveEntryCode": 16,
  "RequestId": 20,
  "EmployeeCode": 17125,
  "LeaveYear": 2016,
  "LeaveTypeCode": 1,
  "BaseType": "ess",
  "LeaveDate": "2016-09-05T00:00:00",
}
}
*//
NSDictionay *leaveDetailDict = [dict objectForKey:@"LeaveDetail"];//get dict have key LeaveDetail
NSLog(@"%@",leaveDetailDict[@"LeaveDate"];
Rin
  • 84
  • 10