I'm creating a UITableView with some aggregated data. Along the way, Section Headings need to be used in sorting and grouping the table view cells.
The issue is I would like to use a Transient Property within the NSFetchRequest to generate section headings & results sorts. The issue is that whilst setting up the NSFetchRequest I receive a ''NSInvalidArgumentException', reason: 'Invalid keypath player.fullName passed to setPropertiesToFetch'.
The main entity for the NSFetchRequest is a Player entity with to properties: firstName & lastName. To sort and group the data a transient property 'fullName' has been introduced. This is a simple concatenation of the lastName and firstName properties.
Things tried so far are:
a) Defining the -(NSString*)fullName method
b) Defining a @property (nonatomic,readonly) NSString *fullName
c) Adding a @dynamic fullName
d) Adding the fullName attribute to the Player entity & making it transient.
Are there any ideas or is there noway to select transient properties in a NSFetchRequest that includes a group by clause.
Any help appreciated.
Transient attributes are properties that you define as part of the model, but that are not saved to the persistent store as part of an entity instance's data. Core Data does track changes you make to transient properties, so they are recorded for undo operations.
Transient means that the value is stored in memory on the object graph. Computed means that the value is stored nowhere and is calculated in the getter. Both are distinct from the classic non-transient attribute which is stored on the object graph and is saved to disk.
Well in the end it seems including a transient property in a group by NSFetchResults with a Group By is not possible.
Great suggestion by jrturton got close. In the end, the transient property fullName was easy enough to generate on update to the entity and only updated very infrequently so the solution was to stop using a transient property and make a fully fledged attribute. Just think of it as extreme denormalisation.
the solution was to setup 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 the fullName as a property of the Player entity and removed my issues. Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With