开发者

Core data - FetchedResultController returning complicated data structures?

开发者 https://www.devze.com 2023-04-13 00:38 出处:网络
So I have the following structure.Basically a tree view. Each node has a set (NSSet of nodes), each node is a object that contains an NSD开发者_如何学运维ate.

So I have the following structure.Basically a tree view. Each node has a set (NSSet of nodes), each node is a object that contains an NSD开发者_如何学运维ate.

-4
-1
   -3
   -2
-5
   -7
   -6
   -8

Is it possible to write a Core data query that returns the following result (Each node contains information about it's parent)

{1,2,3,4,5,6,7,8}

Items in each level should be sorted by date


Have you tried NSSortDescriptor... for ex:

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"timeStamp" ascending:NO];

More tutorial from this site.


Short answer; no.

First, Core Data works with objects not raw values like this.

Second, a NSFetchedResultsController is designed to return a set of objects that are of the same entity type and potentially separated into sections. What you are describing is a multi-level structure and does not fit into the goal of the NSFetchedResultsController.

Update

If you are just looking to get back a NSArray of XEntity sorted by yProperty without regard to the parent/child relationship within XEntity then you don't need a NSFetchedResultsController. Just create a NSFetchedRequest with the -setEntity: set to XEntity and add a NSSortDescriptor that sorts on yProperty and execute the fetch against the NSManagedObjectContext.

If you want to be updated when that data changes then you would want to use a NSFetchedResultsController with that same NSFetchRequest.

0

精彩评论

暂无评论...
验证码 换一张
取 消