循环遍历NSArray来收集特定对象
我现在无法集中注意力,并且在找出以下问题的解决方案时遇到问题:
我有一个由 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不是计算距离,然后找到 10 个最近的对象,而是
Object-X[i]
的Object-Y[0]
和Object-Y[1]
),同时Object-Y[0]
和Object-Y[1]
当块/线程完成时,它们可以将最大对象添加到大批。
Instead of calculating distance, and then finding the 10 closest objects, maybe
Object-Y[0]
andObject-Y[1]
of someObject-X[i]
) whileObject-Y[0]
andObject-Y[1]
When the blocks/threads finish, they can add the max objects to an array.
目前尚不完全清楚距离存储在哪里,但如果它在 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]"]
.