Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.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
Iphone ios-CoreData中已排序的已获取属性_Iphone_Objective C_Core Data - Fatal编程技术网

Iphone ios-CoreData中已排序的已获取属性

Iphone ios-CoreData中已排序的已获取属性,iphone,objective-c,core-data,Iphone,Objective C,Core Data,如何使用fetched属性创建排序数组?我是谓词编程新手 假设有两个实体:“MyEntity”和“Image”MyEntity“与名为“图像”的“图像”有一对多的关系。 “Image”有两个属性:“Image”和“index”,我想使用“index”作为排序键对图像进行排序 我想在“MyEntity”上有一个获取的属性“sortedImages”,它将返回“images”的排序版本 我以前做的是加载所有图像并在内存中排序并存储结果,但我发现这可能会占用太多内存 - (NSArray *)sort

如何使用fetched属性创建排序数组?我是谓词编程新手

假设有两个实体:“MyEntity”和“Image”MyEntity“与名为“图像”的“图像”有一对多的关系。 “Image”有两个属性:“Image”和“index”,我想使用“index”作为排序键对图像进行排序

我想在“MyEntity”上有一个获取的属性“sortedImages”,它将返回“images”的排序版本

我以前做的是加载所有图像并在内存中排序并存储结果,但我发现这可能会占用太多内存

- (NSArray *)sortedImages {
    if (!sortedImages) {
        NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"index" ascending:YES];
        sortedImages = [self.images sortedArrayUsingDescriptors:[NSArray arrayWithObject:descriptor]];
        [sortedImages retain];
    }
    return sortedImages;
}

不确定fetchedProperty是否是此处的正确解决方案,但您可以在父实体的managedObjectContext上创建NSFetchRequest,并在键“index”上使用NSSortDescriptor。这将返回一个“有故障”排序的图像对象数组。

图像属性是实际的图像数据吗?如果是这样,您可能需要存储文件路径,而不是实际数据。如果您这样做,那么您不应该遇到任何内存问题,您可以让您使用存储的文件路径查看和加载映像。@sosborn Yes。这些图片是从互联网上下载的,虽然很小但很多。我将考虑您的解决方案,但我仍然想知道如何使用取回的属性,因为我还有许多其他需要排序的实体也需要更改。