使用 Objective-C 中的精确 int 字典值过滤字典的 NSMutableArray
Filter NSMutableArray of dictionary with an exact int dictionary value in Objective-C
我有一个包含 nsdictionary 对象的 NSMutableArray。
`[
{
"IId": 0,
"BookSLNo": 0,
"RollNoOrEmpId": "0",
"BatchId": 38,
"Batch": "NA",
"UserId": 20,
"Name": "Kaiser Ahmed Khan",
"NickName": "",
"GenderId": 1,
"Gender": "Male",
"DateOfBirth": "01/Jan/2000",
"DateOfBirthYMD": "20000001",
"DesignationId": 8,
"Designation": "Extra Assistant Commissioner of Taxes",
"ZoneId": 12,
"Zone": "Taxes Appeal Zone-1 Dhaka",
"RangeId": 15,
"Range": "NA",
"Circle": "0",
"WorkingDistrictId": 13,
"WorkingDistrict": "Dhaka",
"HighestDegree": "",
"SubjectName": "",
"University": "",
"BloodGroupId": "1",
"BloodGroup": "NA",
"FatherName": "",
"MotherName": "",
"MarriageDate": "/Date(946713600000)/",
"SpouseName": "",
"SpouseBloodGroupId": "0",
"SpouseBloodGroup": "",
"SpouseProfession": "",
"Child1Name": "",
"Child1GenderId": 0,
"Child1Gender": "",
"Child2Name": "",
"Child2GenderId": 0,
"Child2Gender": "",
"Child3Name": "",
"Child3GenderId": 0,
"Child3Gender": "",
"ParmHouseNo": "",
"ParmStreetNo": "",
"ParmPostOffice": "",
"ParmThana": "",
"ParmDistrictId": 12,
"ParmDistrict": "Cox's Bazar",
"PresHouseNo": "",
"PresStreetNo": "",
"PresPostOffice": "",
"PresThana": "",
"PresDistrictId": 0,
"PresDistrict": "",
"ResidentialPhone": "",
"Mobile": "01711372588",
"EMailId": "kaiserahmedkhan@gmail.com",
"FacebookId": "",
"SkypeId": "",
"JoiningDate": "01/Jan/2007",
"FirstJoinedAsId": 0,
"FirstJoinedAs": "",
"Picture": null,
"PictureFamily": null,
"UserGroupId": 2,
"UserGroup": null,
"SectionId": 1,
"Section": null,
"DepartmentId": 1,
"Department": null,
"CreateDate": "/Date(1573221227000)/",
"CreatedBy": 0,
"ModifyDate": "/Date(-62135568000000)/",
"ModifyBy": 0,
"ExecuteType": null,
"PresAddress": ",,,,,,,",
"PictureUrl": "http://taxdirectorybd.com/upload/UserImages/Profile/20.jpg",
"PictureFamilyUrl": "http://taxdirectorybd.com/upload/UserImages/Wal/20.jpg",
"JoiningDateYMD": "01/Jan/2007",
"MarriageDateSTR": "01/01/2000",
"IsFreedomFighter": null,
"Others": null
},
{
"IId": 0,
"BookSLNo": 0,
"RollNoOrEmpId": "0",
"BatchId": 38,
"Batch": "NA",
"UserId": 21,
"Name": "Nasreen Ara",
"NickName": "",
"GenderId": 2,
"Gender": "Female",
"DateOfBirth": "01/Jan/2000",
"DateOfBirthYMD": "20000001",
"DesignationId": 8,
"Designation": "Extra Assistant Commissioner of Taxes",
"ZoneId": 12,
"Zone": "Taxes Appeal Zone-1 Dhaka",
"RangeId": 15,
"Range": "NA",
"Circle": "0",
"WorkingDistrictId": 13,
"WorkingDistrict": "Dhaka",
"HighestDegree": "",
"SubjectName": "",
"University": "",
"BloodGroupId": "1",
"BloodGroup": "NA",
"FatherName": "",
"MotherName": "",
"MarriageDate": "/Date(946713600000)/",
"SpouseName": "",
"SpouseBloodGroupId": "0",
"SpouseBloodGroup": "",
"SpouseProfession": "",
"Child1Name": "",
"Child1GenderId": 0,
"Child1Gender": "",
"Child2Name": "",
"Child2GenderId": 0,
"Child2Gender": "",
"Child3Name": "",
"Child3GenderId": 0,
"Child3Gender": "",
"ParmHouseNo": "",
"ParmStreetNo": "",
"ParmPostOffice": "",
"ParmThana": "",
"ParmDistrictId": 0,
"ParmDistrict": "",
"PresHouseNo": "",
"PresStreetNo": "",
"PresPostOffice": "",
"PresThana": "",
"PresDistrictId": 0,
"PresDistrict": "",
"ResidentialPhone": "",
"Mobile": "01552371912",
"EMailId": "nasreenara65@gmail.com",
"FacebookId": "",
"SkypeId": "",
"JoiningDate": "01/Jan/2000",
"FirstJoinedAsId": 0,
"FirstJoinedAs": "",
"Picture": null,
"PictureFamily": null,
"UserGroupId": 2,
"UserGroup": null,
"SectionId": 1,
"Section": null,
"DepartmentId": 1,
"Department": null,
"CreateDate": "/Date(1573221354000)/",
"CreatedBy": 0,
"ModifyDate": "/Date(-62135568000000)/",
"ModifyBy": 0,
"ExecuteType": null,
"PresAddress": ",,,,,,,",
"PictureUrl": "http://taxdirectorybd.com/upload/UserImages/Profile/21.jpg",
"PictureFamilyUrl": "http://taxdirectorybd.com/upload/UserImages/Wal/21.jpg",
"JoiningDateYMD": "01/Jan/2000",
"MarriageDateSTR": "01/01/2000",
"IsFreedomFighter": null,
"Others": null
}
]
我正在尝试使用关键字 UserId 来过滤数组。但是无法过滤。我这样试过。
NSString* userId=userInfo[@"UserId"];
NSPredicate* predicate=[NSPredicate predicateWithFormat:@"(UserId == %@)",userId]; NSArray* filteredArrays = [allData filteredArrayUsingPredicate:predicate];
此处 UserId 包含字符串格式的整数值。 Whie 尝试使用提供的代码片段进行过滤,
它总是返回 O 对象。
您不能将字符串与这样的数字进行比较。所以只需取 intValue 并将其作为 int 进行比较。
NSString *userId = userInfo[@"UserId"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"UserId = %d", userId.intValue];
NSArray *filtered = [allData filteredArrayUsingPredicate:predicate];
我有一个包含 nsdictionary 对象的 NSMutableArray。
`[
{
"IId": 0,
"BookSLNo": 0,
"RollNoOrEmpId": "0",
"BatchId": 38,
"Batch": "NA",
"UserId": 20,
"Name": "Kaiser Ahmed Khan",
"NickName": "",
"GenderId": 1,
"Gender": "Male",
"DateOfBirth": "01/Jan/2000",
"DateOfBirthYMD": "20000001",
"DesignationId": 8,
"Designation": "Extra Assistant Commissioner of Taxes",
"ZoneId": 12,
"Zone": "Taxes Appeal Zone-1 Dhaka",
"RangeId": 15,
"Range": "NA",
"Circle": "0",
"WorkingDistrictId": 13,
"WorkingDistrict": "Dhaka",
"HighestDegree": "",
"SubjectName": "",
"University": "",
"BloodGroupId": "1",
"BloodGroup": "NA",
"FatherName": "",
"MotherName": "",
"MarriageDate": "/Date(946713600000)/",
"SpouseName": "",
"SpouseBloodGroupId": "0",
"SpouseBloodGroup": "",
"SpouseProfession": "",
"Child1Name": "",
"Child1GenderId": 0,
"Child1Gender": "",
"Child2Name": "",
"Child2GenderId": 0,
"Child2Gender": "",
"Child3Name": "",
"Child3GenderId": 0,
"Child3Gender": "",
"ParmHouseNo": "",
"ParmStreetNo": "",
"ParmPostOffice": "",
"ParmThana": "",
"ParmDistrictId": 12,
"ParmDistrict": "Cox's Bazar",
"PresHouseNo": "",
"PresStreetNo": "",
"PresPostOffice": "",
"PresThana": "",
"PresDistrictId": 0,
"PresDistrict": "",
"ResidentialPhone": "",
"Mobile": "01711372588",
"EMailId": "kaiserahmedkhan@gmail.com",
"FacebookId": "",
"SkypeId": "",
"JoiningDate": "01/Jan/2007",
"FirstJoinedAsId": 0,
"FirstJoinedAs": "",
"Picture": null,
"PictureFamily": null,
"UserGroupId": 2,
"UserGroup": null,
"SectionId": 1,
"Section": null,
"DepartmentId": 1,
"Department": null,
"CreateDate": "/Date(1573221227000)/",
"CreatedBy": 0,
"ModifyDate": "/Date(-62135568000000)/",
"ModifyBy": 0,
"ExecuteType": null,
"PresAddress": ",,,,,,,",
"PictureUrl": "http://taxdirectorybd.com/upload/UserImages/Profile/20.jpg",
"PictureFamilyUrl": "http://taxdirectorybd.com/upload/UserImages/Wal/20.jpg",
"JoiningDateYMD": "01/Jan/2007",
"MarriageDateSTR": "01/01/2000",
"IsFreedomFighter": null,
"Others": null
},
{
"IId": 0,
"BookSLNo": 0,
"RollNoOrEmpId": "0",
"BatchId": 38,
"Batch": "NA",
"UserId": 21,
"Name": "Nasreen Ara",
"NickName": "",
"GenderId": 2,
"Gender": "Female",
"DateOfBirth": "01/Jan/2000",
"DateOfBirthYMD": "20000001",
"DesignationId": 8,
"Designation": "Extra Assistant Commissioner of Taxes",
"ZoneId": 12,
"Zone": "Taxes Appeal Zone-1 Dhaka",
"RangeId": 15,
"Range": "NA",
"Circle": "0",
"WorkingDistrictId": 13,
"WorkingDistrict": "Dhaka",
"HighestDegree": "",
"SubjectName": "",
"University": "",
"BloodGroupId": "1",
"BloodGroup": "NA",
"FatherName": "",
"MotherName": "",
"MarriageDate": "/Date(946713600000)/",
"SpouseName": "",
"SpouseBloodGroupId": "0",
"SpouseBloodGroup": "",
"SpouseProfession": "",
"Child1Name": "",
"Child1GenderId": 0,
"Child1Gender": "",
"Child2Name": "",
"Child2GenderId": 0,
"Child2Gender": "",
"Child3Name": "",
"Child3GenderId": 0,
"Child3Gender": "",
"ParmHouseNo": "",
"ParmStreetNo": "",
"ParmPostOffice": "",
"ParmThana": "",
"ParmDistrictId": 0,
"ParmDistrict": "",
"PresHouseNo": "",
"PresStreetNo": "",
"PresPostOffice": "",
"PresThana": "",
"PresDistrictId": 0,
"PresDistrict": "",
"ResidentialPhone": "",
"Mobile": "01552371912",
"EMailId": "nasreenara65@gmail.com",
"FacebookId": "",
"SkypeId": "",
"JoiningDate": "01/Jan/2000",
"FirstJoinedAsId": 0,
"FirstJoinedAs": "",
"Picture": null,
"PictureFamily": null,
"UserGroupId": 2,
"UserGroup": null,
"SectionId": 1,
"Section": null,
"DepartmentId": 1,
"Department": null,
"CreateDate": "/Date(1573221354000)/",
"CreatedBy": 0,
"ModifyDate": "/Date(-62135568000000)/",
"ModifyBy": 0,
"ExecuteType": null,
"PresAddress": ",,,,,,,",
"PictureUrl": "http://taxdirectorybd.com/upload/UserImages/Profile/21.jpg",
"PictureFamilyUrl": "http://taxdirectorybd.com/upload/UserImages/Wal/21.jpg",
"JoiningDateYMD": "01/Jan/2000",
"MarriageDateSTR": "01/01/2000",
"IsFreedomFighter": null,
"Others": null
}
]
我正在尝试使用关键字 UserId 来过滤数组。但是无法过滤。我这样试过。
NSString* userId=userInfo[@"UserId"];
NSPredicate* predicate=[NSPredicate predicateWithFormat:@"(UserId == %@)",userId]; NSArray* filteredArrays = [allData filteredArrayUsingPredicate:predicate];
此处 UserId 包含字符串格式的整数值。 Whie 尝试使用提供的代码片段进行过滤, 它总是返回 O 对象。
您不能将字符串与这样的数字进行比较。所以只需取 intValue 并将其作为 int 进行比较。
NSString *userId = userInfo[@"UserId"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"UserId = %d", userId.intValue];
NSArray *filtered = [allData filteredArrayUsingPredicate:predicate];