简体   繁体   English

遍历NSArray收集特定对象

[英]Loop through NSArray to collect specific objects

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. 我有一个5个NSObjects数组,Object-X。 Each objects has two objects, Object-Y. 每个对象都有两个对象,即Object-Y。 Each of these two objects have a 50 objects, Object-Z, inside them. 这两个对象中的每个对象内部都有50个对象,即Z对象。

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. 五十个对象(对象Z)中的每一个都有一个CLLocation。 I first run through all 500 objects and calculate the distance from the users current location and the objects. 我首先遍历所有500个对象,并计算出与用户当前位置和对象的距离。

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. 然后,我想做的是(最好是在可能的情况下,最好同时进行)是从每个Object-X中的每个Object-Y中获取最接近的Object-Z并将其插入到数组中,因此最终得到10个对象。

Instead of calculating distance, and then finding the 10 closest objects, maybe 而不是计算距离, 然后找到10个最接近的对象,也许

  1. dispatch, say, 5 blocks/threads (using GCD ... or a common multi-threaded approach), which would each 调度5个块/线程(使用GCD ...或常见的多线程方法),每个
  2. calculate 100 distances (for Object-Y[0] and Object-Y[1] of some Object-X[i] ) while 计算100个距离(对于某些Object-X[i] Object-Y[0]Object-Y[1] Object-X[i]
  3. keeping track of the objects with the min distance, for both Object-Y[0] and Object-Y[1] Object-Y[0]Object-Y[1]的最小距离跟踪对象

When the blocks/threads finish, they can add the max objects to an array. 当块/线程完成时,它们可以将max对象添加到数组中。

距离的存储位置尚不完全清楚,但如果在ObjectZ上,则可以执行[objectXs valueForKeyPath:@"objectYs.objectZs.@min.distance"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM