我是IOS和Swift语言的新手,现在我在Swift3工作。
DetailsArray:
[{
bookId = abcd;
bookName = "MyBook";
bookThumbImage = ".jpg"
},
{
bookId = efgh;
bookName = "MyBook1";
bookThumbImage = "bookefgh.jpg"
},
{
bookId = ijkl;
bookName = "MyBook2";
bookThumbImage = ".jpg"
}
]
当我打印我的现有IdListArray对象时,采用以下给定格式,
IdListArray:
▿ Optional<"NSMutableArray">
▿ some : 2 elements
- 0 : abcd
- 1 : ijkl
现在我需要匹配这两个数组(IdListArray&amp; DetailsArray),以从我的DetailsArray中获取匹配的行记录
必需输出:
[{
bookId = abcd;
bookName = "MyBook";
bookThumbImage = ".jpg"
},
{
bookId = ijkl;
bookName = "MyBook2";
bookThumbImage = ".jpg"
}]
谢谢,
答案 0 :(得分:0)
您可以使用此代码:
var arrMatchingId:NSMutableArray = NSMutableArray()
var arrNotMatchingId:NSMutableArray = NSMutableArray()
for data in arrList{
let id = (data as! NSDictionary).value(forKey: "bookId")
if arrID.contains(id!){
arrMatchingId.add(data) //Id Matched
}else{
arrNotMatchingId.add(data)// Id Not Matched
}
}
print(arrMatchingId) // This is the array with matched ID
print(arrNotMatchingId) //This is the array with Unmatched array