循环遍历NSArray来收集特定对象

发布于 2024-10-29 02:15:28 字数 918 浏览 1 评论 0原文

我现在无法集中注意力,并且在找出以下问题的解决方案时遇到问题:

我有一个由 5 个 NSObjects 组成的数组,Object-X。每个对象有两个对象,Object-Y。这两个物体内部各有一个 50 个物体,Object-Z。

像这样的东西。

Object-X 0:
    Object-Y 0:
        Object-Z: 0
        Object-Z: 1
        Object-Z: 2
        ...
    Object-Y 1:
        Object-Z: 0
        Object-Z: 1
        Object-Z: 2
        ...
Object-X 1:
    Object-Y 0:
        Object-Z: 0
        Object-Z: 1
        Object-Z: 2
        ...
    Object-Y 1:
        Object-Z: 0
        Object-Z: 1
        Object-Z: 2
        ...
Object-X 2:
    Object-Y 0:
        Object-Z: 0
        Object-Z: 1
        Object-Z: 2
        ...
    Object-Y 1:
        Object-Z: 0
        Object-Z: 1
        Object-Z: 2
        ...
 ...

五十个对象 (Object-Z) 中的每一个都有一个 CLLocation。我首先遍历所有 500 个对象并计算用户当前位置和对象的距离。

然后我想要做的(最好是同时,如果可能的话)是从每个对象 X 中的每个对象 Y 中取出最接近的对象 Z 并将其插入到一个数组中,所以我最终得到 10 个对象。

I can't gather my thoughts at the moments and have problems figuring out a solution to the following:

I have an array of 5 NSObjects, Object-X. Each objects has two objects, Object-Y. Each of these two objects have a 50 objects, Object-Z, inside them.

Something like this.

Object-X 0:
    Object-Y 0:
        Object-Z: 0
        Object-Z: 1
        Object-Z: 2
        ...
    Object-Y 1:
        Object-Z: 0
        Object-Z: 1
        Object-Z: 2
        ...
Object-X 1:
    Object-Y 0:
        Object-Z: 0
        Object-Z: 1
        Object-Z: 2
        ...
    Object-Y 1:
        Object-Z: 0
        Object-Z: 1
        Object-Z: 2
        ...
Object-X 2:
    Object-Y 0:
        Object-Z: 0
        Object-Z: 1
        Object-Z: 2
        ...
    Object-Y 1:
        Object-Z: 0
        Object-Z: 1
        Object-Z: 2
        ...
 ...

Each of the fifty objects (Object-Z) has an CLLocation. I first run through all 500 objects and calculate the distance from the users current location and the objects.

What I would like to then do (preferably at the same time, if possible) is to take the closest Object-Z from each Object-Y in each Object-X and insert it into an array, so I end up with 10 objects.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等风来 2024-11-05 02:15:28

不是计算距离,然后找到 10 个最近的对象,而是

  1. 分派 5 个块/线程(使用 GCD ...或常见的多线程方法),每个块/线程将
  2. 计算 100 个距离(对于某些 Object-X[i]Object-Y[0]Object-Y[1]),同时
  3. 跟踪具有最小距离的对象,对于 Object-Y[0]Object-Y[1]

当块/线程完成时,它们可以将最大对象添加到大批。

Instead of calculating distance, and then finding the 10 closest objects, maybe

  1. dispatch, say, 5 blocks/threads (using GCD ... or a common multi-threaded approach), which would each
  2. calculate 100 distances (for Object-Y[0] and Object-Y[1] of some Object-X[i]) while
  3. keeping track of the objects with the min distance, for both Object-Y[0] and Object-Y[1]

When the blocks/threads finish, they can add the max objects to an array.

寒尘 2024-11-05 02:15:28

目前尚不完全清楚距离存储在哪里,但如果它在 ObjectZ 上,那么您可以执行类似 [objectXs valueForKeyPath:@"[电子邮件受保护]"]

It's not entirely clear where the distance is stored, but if it's on the ObjectZs, then you could do something like [objectXs valueForKeyPath:@"[email protected]"].

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文