NSArray 子集并从动态parentArray 排序
我遇到了一个大问题,即如何增强图形视图的方法。
我通过 coredata 检索数组。
存在父父<--->>条目实体关系。
我需要结合父 <-->> 的结果按 NSDate 排序的数组中的条目关系,这非常简单,父级可以根据添加它的时间戳(NSDate)有多个条目。
我将 fetchRequest 与以下内容一起使用:
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"timeStamp" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"ANY forParent.entries == %@",selectedTrack]
使用该谓词,我可以将多个父项的父项条目取出到不同的数组集中。
但我想要一个基于时间戳排序的组合结果
例如,
NSArray Result_ParentA = [entries sortedBy timeStamp]; {A0 ,A1, A2, A3, A5} (5)
NSArray Result_ParentB = [entries sortedBy TimeStamp]; {B0, B1, B2, B3, B4} (5)
NSArray Result_ParentC = [entries sortedBy TimeStamp]; {C0, C1, C2, C3, C4 C5 } (6)
这里需要注意两点, 1- 数组 Result_ParentA 在日期“4”上没有条目对象,同样,B 数组在“5”上没有条目,让我们假设这些数字是它们相加的 NSDate。
我想要一个数组,它给我一个数组形式的结果,如下所示:
CombinedSortedArray objectAtIndex:0] = Array{A0, B0, C0} CountRemains 3
CombinedSortedArray objectAtIndex:1] = Array{A1, B1, C1} Count remains 3
CombinedSortedArray objectAtIndex:4] = Array{0.0, B4, C4}
CombinedSortedArray objectAtIndex:5] = Array{A5, 0.0, C5}
//Count of all the subset Arrays remains 3 which is equal to the count of Parents! Only the difference being that a nil result is replaced by 0.0!
2-所有这一切都更加复杂,因为知道父项是一个动态数字,我不知道图中有多少个父项。
也许我应该更改我的获取请求以给我一个排序的数组,并在得到它后做一些小的更改..?
我现在一无所知,感谢任何帮助。
I've run into a big question of an approach in order to fuel a graph view.
I retrieve Arrays via coredata.
A Parent Parent <--->>Entry entity relationship exists.
I need to combine the results of parent <-->> Entry relationship into an array sorted by NSDate, thats pretty easy, a parent could have multiple Entries based on timeStamp (NSDate) of adding it.
I use a fetchRequest with the following:
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"timeStamp" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"ANY forParent.entries == %@",selectedTrack]
Using that predicate I can take out the entries of Parent of multiple parents into different set of Arrays.
But I would like to have a combined result thats sorted Based on TimeStamps
For example,
NSArray Result_ParentA = [entries sortedBy timeStamp]; {A0 ,A1, A2, A3, A5} (5)
NSArray Result_ParentB = [entries sortedBy TimeStamp]; {B0, B1, B2, B3, B4} (5)
NSArray Result_ParentC = [entries sortedBy TimeStamp]; {C0, C1, C2, C3, C4 C5 } (6)
Two points to note here,
1- Array Result_ParentA has no entryObject on date "4th" and likewise, B array has no entry on "5th", lets assume those digits to be their NSDates of adding.
I want to have an array that gives me a result as an Array like:
CombinedSortedArray objectAtIndex:0] = Array{A0, B0, C0} CountRemains 3
CombinedSortedArray objectAtIndex:1] = Array{A1, B1, C1} Count remains 3
CombinedSortedArray objectAtIndex:4] = Array{0.0, B4, C4}
CombinedSortedArray objectAtIndex:5] = Array{A5, 0.0, C5}
//Count of all the subset Arrays remains 3 which is equal to the count of Parents! Only the difference being that a nil result is replaced by 0.0!
2- All this is more complicated by knowing that the Parent is a dynamic number, I can't know how many parents are viewed in the graph..
Perhaps I should change my fetch request to give me a sorted array and do some minor changes after I get it..?
Im clueless now, any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经使用 NSSortDescriptor 获得了一个排序数组(尽管您需要将其设置为获取请求的排序描述符)。通过对“升序”参数说“不”,您所做的就是将它们恢复为最大到最小,而不是最小到最大。 NSSortDescriptor 和 NSPredicate 都是可选参数。如果您想要恢复所有 CoreData 对象,只需删除 NSPredicate 即可。
You are already getting a sorted array with your NSSortDescriptor (though you need to set this to be the sort descriptor of the fetch request). All you did by saying NO to the "ascending" parameter is that you'll get them back largest to smallest instead of smallest to largest. Both the NSSortDescriptor and the NSPredicate are optional parameters. If you want all CoreData objects back, just remove the NSPredicate.