来自indexesOfObjectsPassingTest 的排序数组?
我有一个名为 arrayToFilter 的 myObjects 数组。 myObject 的一个(元素?)是一组贝塞尔路径。我将特定索引(thispath)处的贝塞尔路径与第二条路径进行比较,并使filteredArray仅由路径重叠一定量(20%)的那些对象组成。我使用indexedOfObjectsPassingTest来喜欢这个:
NSIndexSet * index = [[arrayToFilter objectsAtIndexes:index] indexesOfObjectsPassingTest:^BOOL (id obj, NSUInteger idx, BOOL *stop){
MyObject * anobject = obj;
UIBezierPath * thispath = [anobject.allPaths objectAtIndex:i];
NSInteger overlap = [self percentPathBoxOverlap:path: thispath];
return overlap>20;
}];
if ([index count] !=0){
filteredArray = [arrayToFilter objectsAtIndexes:index] ;
}
这工作正常。但我想做的是让filteredArray 与那些重叠值较高的对象一起排序。由于重叠是根据当前路径和此路径动态计算的,因此我不知道如何使用任何排序数组方法。
I have an array of myObjects called arrayToFilter. One (element?) of myObject is an array of bezierpaths. I am comparing the bezierpath at a particular index (thispath) to a second path, and making filteredArray composed of only those objects in which the paths overlapped a certain amount (20%). I used indexedOfObjectsPassingTest to like this:
NSIndexSet * index = [[arrayToFilter objectsAtIndexes:index] indexesOfObjectsPassingTest:^BOOL (id obj, NSUInteger idx, BOOL *stop){
MyObject * anobject = obj;
UIBezierPath * thispath = [anobject.allPaths objectAtIndex:i];
NSInteger overlap = [self percentPathBoxOverlap:path: thispath];
return overlap>20;
}];
if ([index count] !=0){
filteredArray = [arrayToFilter objectsAtIndexes:index] ;
}
This works fine. But what i'd like to do is have filteredArray come out sorted with those object with the higher value for overlap coming out first. since overlap is calculated on the fly based on the current path and thispath, i don't know how to use any of the sorted array methods.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以首先创建一个包含路径和重叠数据的字典数组。这将需要对当前通过过滤器搜索和提取的方法进行一些修改。
现在您可以使用字典的
overlap
键对此数组进行排序。现在,
sortedArray
将具有路径和重叠信息的排序列表。You can start off by creating an array of dictionaries containing both path and the overlap data. This will require some modification to your current approach where you search and extract over filter.
Now you can sort this array using the
overlap
key of the dictionaries.Now
sortedArray
will have the sorted list of path and overlap information.您必须首先对数组进行排序,然后调用
indexesOfObjectsPassingTest
来获取排序后的索引。 sortedArrayUsingComparator:是对数组进行排序的更简单的方法之一,它需要一个块,就像indexesOfObjectsPassingTest
方法。然后您可以在 arrayToFilter 上执行现有的过滤
You'll have to sort the array first, then call
indexesOfObjectsPassingTest
for the sorted indices. sortedArrayUsingComparator: is one of the easier methods of sorting an array, it takes a block just like theindexesOfObjectsPassingTest
method.Then you can perform your existing filtering on the
arrayToFilter