The acquired property will work, and I really used it in my own project with the Post-> Comment relation, which needs to be sorted by the index of the added date.
There are a few caveats: you cannot specify a sort descriptor in a visual editor and specify it in code.
I'm using something like this
// Find the fetched properties, and make them sorted... for (NSEntityDescription *entity in [_managedObjectModel entities]) { for (NSPropertyDescription *property in [entity properties]) { if ([property isKindOfClass:[NSFetchedPropertyDescription class]]) { NSFetchedPropertyDescription *fetchedProperty = (NSFetchedPropertyDescription *)property; NSFetchRequest *fetchRequest = [fetchedProperty fetchRequest]; // Only sort by name if the destination entity actually has a "index" field if ([[[[fetchRequest entity] propertiesByName] allKeys] containsObject:@"index"]) { NSSortDescriptor *sortByName = [[NSSortDescriptor alloc] initWithKey:@"index" ascending:YES]; [fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortByName]]; } } } }
In the My Post object, I have a selected property called sortedComments, which is defined as:
post == $FETCH_SOURCE
where posts relate to many "comments" and comments have a "post" backlink
Contrary to other answers here: The benefits of using a selected property, such as CoreData, take care of caching and invalidating the cache as comments on a message or indeed a message that belongs to them.
source share