[英]how do I search an array of objects and return only those objects with certain uids in objective c
I have an array of uids, and another array of objects. 我有一个uid数组和另一个对象数组。 The objects structure is such that it has a name and a uid.
对象结构是这样的,它具有名称和uid。 I would like to search the array or objects, and return an array of those objects that match the uids from the first array.
我想搜索数组或对象,并返回与第一个数组中的uid匹配的那些对象的数组。 I was exploring using undersore.m but I'm not sure if this is appropriate.
我正在使用undersore.m探索,但不确定是否合适。
Use a simple loop: 使用一个简单的循环:
NSArray *uids = ... // your array of UIDs
NSArray *objects = ... // your array of objects with a name and uid
NSMutableArray *matches = [NSMutableArray array];
for (SomeClass *object in objects) {
if ([uids containsObject:object.uid]) {
[matches addObject:object];
}
}
matches
will contain the matching objects. matches
将包含匹配的对象。
Obviously you need to change SomeClass
to your actual class that has the name and uid. 显然,您需要将
SomeClass
更改为具有名称和uid的实际类。 And I'm assuming your class has a uid
property. 我假设您的类具有
uid
属性。 Adjust as needed. 根据需要进行调整。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.