Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting CoreData:基于中使用的谓词/数组进行排序_Sorting_Core Data_Nspredicate - Fatal编程技术网

Sorting CoreData:基于中使用的谓词/数组进行排序

Sorting CoreData:基于中使用的谓词/数组进行排序,sorting,core-data,nspredicate,Sorting,Core Data,Nspredicate,我有一个CoreData存储,并希望维护REST服务提供的排序顺序。CoreData中的对象有一个guid属性,其余提供的数组(guid)被排序。我希望在从CoreData获取对象后保持这种排序 我正在提取中使用以下NSPredicate: [NSPredicate predicateWithFormat:@“guid IN%@”,wishlistGUIDs] 其中wishlistGUIDs是为相关对象提供的其余guid数组 在维护wishlistGUIDs顺序的同时,是否有方法获取结果?我已经

我有一个CoreData存储,并希望维护REST服务提供的排序顺序。CoreData中的对象有一个
guid
属性,其余提供的数组(guid)被排序。我希望在从CoreData获取对象后保持这种排序

我正在提取中使用以下
NSPredicate

[NSPredicate predicateWithFormat:@“guid IN%@”,wishlistGUIDs]

其中wishlistGUIDs是为相关对象提供的其余guid数组


在维护
wishlistGUIDs
顺序的同时,是否有方法获取结果?我已经探索过如何使用
NSSortDescriptor
,并通过迭代
wishlistGUIDs
来组装一个疯狂的排序描述符数组,但它似乎过于复杂,而且完全是“错误的”。

您能将自己限制在iOS 5/Lion上吗?这看起来像是有序关系的一个很好的用例(它作为一个
ensorderedset
)。您将拥有一个核心数据实体“wishlist”,它将包含有序的guid


除此之外,我认为你将不得不做一些丑陋的事情,比如为guid列表保留自己的序列号。

你能将自己限制在iOS 5/Lion吗?这看起来像是有序关系的一个很好的用例(它作为一个
ensorderedset
)。您将拥有一个核心数据实体“wishlist”,它将包含有序的guid


除此之外,我认为您将不得不做一些丑陋的事情,比如为GUI列表维护自己的序列号。

以下是我为解决此类问题而采取的额外步骤:

定义方法:

NSInteger gidSort(Guild* num1, Guild* num2, void *context) {
    NSArray* wishlistGUIDs = (NSArray*)context;
    int v1 = [wishlistGUIDs indexOfObject:num1.guid];
    int v2 = [wishlistGUIDs indexOfObject:num2.guid];
    if (v1 < v2)
        return NSOrderedAscending;
    else if (v1 > v2)
        return NSOrderedDescending;
    else
        return NSOrderedSame;
}

以下是我为解决此类问题而采取的额外步骤:

定义方法:

NSInteger gidSort(Guild* num1, Guild* num2, void *context) {
    NSArray* wishlistGUIDs = (NSArray*)context;
    int v1 = [wishlistGUIDs indexOfObject:num1.guid];
    int v2 = [wishlistGUIDs indexOfObject:num2.guid];
    if (v1 < v2)
        return NSOrderedAscending;
    else if (v1 > v2)
        return NSOrderedDescending;
    else
        return NSOrderedSame;
}