[英]Compare Two Different Structured Arrays in Swift3
I am new to IOS as well as Swift Language, now I am working in Swift3. 我是IOS和Swift语言的新手,现在我正在Swift3中工作。
DetailsArray: DetailsArray:
[{
bookId = abcd;
bookName = "MyBook";
bookThumbImage = ".jpg"
},
{
bookId = efgh;
bookName = "MyBook1";
bookThumbImage = "bookefgh.jpg"
},
{
bookId = ijkl;
bookName = "MyBook2";
bookThumbImage = ".jpg"
}
]
When i print my Existing IdListArray Object is in the below given format, 当我以以下给定格式打印我现有的IdListArray对象时,
IdListArray: IdListArray:
▿ Optional<"NSMutableArray">
▿ some : 2 elements
- 0 : abcd
- 1 : ijkl
Now i need to match these two Arrays (IdListArray & DetailsArray), to get the matched row record from my DetailsArray 现在我需要匹配这两个数组(IdListArray和DetailsArray),以从我的DetailsArray中获取匹配的行记录
Required Output: 要求的输出:
[{
bookId = abcd;
bookName = "MyBook";
bookThumbImage = ".jpg"
},
{
bookId = ijkl;
bookName = "MyBook2";
bookThumbImage = ".jpg"
}]
Thanks, 谢谢,
You can use this code: 您可以使用以下代码:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.