Master Data - Using Transient Properties in a Group by

I am creating a UITableView with some aggregated data. Along the way, section headers should be used to sort and group table cells.

The problem is that I would like to use the Transient Property in NSFetchRequest to generate section headers and sort results. The problem is that when setting up NSFetchRequest I get "NSInvalidArgumentException", the reason is: "Invalid player.fullName keyword passed to setPropertiesToFetch".

The main NSFetchRequest object is a Player object with the properties: firstName and lastName. To sort and group data, the passient "fullName" property was introduced. This is a simple concatenation of the lastName and firstName properties.

So far, the following things have existed:

a) FullName method definition - (NSString *)

b) Definition of @property (non-atomic, read-only) NSString * fullName

c) Adding @dynamic fullName

d) Adding the fullName attribute to the Player object and transition to it.

Are there any ideas or are there right now to select transient properties in NSFetchRequest, which includes a group by clause.

Any help was appreciated.

+6
source share
2 answers

Well, after all, it seems like a transient property in the NSFetchResults group with the By group is not possible.

A great jrturton offer has come close. In the end, the passient fullName property was quite simple to generate when updating for the object and was updated very rarely, so the solution was to stop using the transient property and make a full attribute. Think of it as extreme denormalization.

the solution was to configure the following

-(void)setLastName:(NSString*)aName { [self willChangeValueForKey: @"lastName" ]; [self setPrimitiveValue: aName forKey: @"lastName" ]; [self updateFullName]; [self didChangeValueForKey: @"lastName" ]; } -(void)setFirstName:(NSString*)aName { [self willChangeValueForKey: @"firstName" ]; [self setPrimitiveValue: aName forKey: @"firstName"]; [self updateFullName]; [self didChangeValueForKey: @"firstName" ]; } 

This updates fullName as a property of the Player object and removes my problems. Hope this helps.

+3
source

You cannot include temporary properties in your select query, but you can use them for the key path name of the section name if they exit in the same order.

Try sorting your query query lastName and firstName (two separate sort descriptors in an array), then use player.fullName as the path of the section name key when creating the result controller you selected (only a and b from the list above),

+2
source

Source: https://habr.com/ru/post/908879/


All Articles