检查一个NSArray的内容是否在另一个数组中 [英] Check that the contents of one NSArray are all in another array
本文介绍了检查一个NSArray的内容是否在另一个数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 NSArray
在字符串对象中的名称如下: @ [@john,@smith,@alex ,
,我有另一个包含很多名字的数组。如何检查第一个数组中的所有对象是否在第二个?
@louis]
I have one NSArray
with names in string objects like this:@[@"john", @"smith", @"alex",
@"louis"]
, and I have another array that contains lots of names. How can I check that all the objects in the first array are in the second?
推荐答案
NSSet
做你所需要的。如果我们忽略性能问题,那么这将在一行中完成你所需要的:
NSSet
does what you need. If we disregard performance issues for a moment, then this will do what you need in a single line:
BOOL isSubset = [[NSSet setWithArray: array1] isSubsetOfSet: [NSSet setWithArray: mainArray]];
这篇关于检查一个NSArray的内容是否在另一个数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文