简体   繁体   English

我如何搜索对象数组并仅返回目标c中具有特定uid的那些对象

[英]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.

相关问题 如何在Objective C中的对象数组中获取对象的属性? - How do I get a property of an object in an array of those objects in Objective C? 如何解析Objective-C中的对象数组? - How do I parse through an array of objects in Objective-C? 如何将一系列对象从iPhone传递到Apple Watch。 仅应传递某些字段 - How do I pass an array of objects from iPhone to Apple Watch. Only certain fields should be passed iOS / Objective-C:使用对象数组搜索字符串元素 - IOS/Objective-C: Search string element with array of objects 如何在objective-c中初始化对象数组,类似于swift - How to init array of objects in objective-c, similar to swift 如何在Objective C中访问字典数组并使用字典对象? - How to access array of dictionaries and use the dictionary objects in Objective C? 如何在Objective-C中添加和更新二维数组的对象? - How to add and update the objects of two dimensional array in objective-c? 如何将多个对象添加到数组 - Objective C / iOS - How to add multiple Objects to Array - Objective C / iOS 如何在Objective C中将两个数组的对象作为对象和键添加到第三个数组 - How to add two array's objects as objects and keys to the third array in Objective C 将UIImageView对象添加到数组(目标C) - Add UIImageView objects to an array (Objective C)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM