Need Help Understanding Transient Property in IOS Core Data

740 Views Asked by At

I don't understand why things have to be so difficult in core data. I have an entity that has 2 decimal attributes, "extended" and "qty"

All I want to do is extend these 2 values (multiply) and refer to this calculated value in a fetch. such as NSDecimalNumber * extendedPrice = [self.qty decimalNumberByMultiplyingBy:self.rate];

But in other cases I will want to @sum: this extended value attribute.

The web-available documentation and examples is very weak on how to do this which to me seems a very common thing to do.

Am I on the wrong track thinking I need a transient attribute and an awakefromfetch call? I get a crash when I try and refer to a transient attribute in a fetch.

1

There are 1 best solutions below

2
On

You can't use transient attributes in fetch requests if you're using an SQLite store. This is because the fetch predicate is converted into an SQL query and no code is actually called. If the attribute doesn't exist in the store then it can't be used.

If you wanted to fetch the objects and then filter / sum them then that will work with a transient because at that point inTime you actually have the instances of the objects.