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?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- back button text does not change
- Change sort order of strings includes with a speci
- iOS (objective-c) compression_decode_buffer() retu
相关文章
- 现在使用swift开发ios应用好还是swift?
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- didBeginContact:(SKPhysicsContact *)contact not in
- Custom Marker performance iOS, crash with result “
NSSet
has the functionality that you are looking for.If we disregard performance issues for a moment, then the following snippet will do what you need in a single line of code:
You can use the concept of
[NSArray containsObject:]
, where your objects will be from your array1 like you say "john","smith","alex","loui"Run a loop and use
isEqualToStiring
to verify whether array1 objects exists in mainArray.If you just need to check if all objects from array1 are in mainArray, you should just use
NSSet
e.g.if you need to check which objects are in mainArray, you should take a look at
NSMutableSet
Use NSArray filteredArrayUsingPredicate: method. Its really fast to find out similar types of object in both arrays
From above code intersect array gives you same objects which are in other array.