1

I have two entities in my app: User & Expense. A user has many expenses. Expense as an attribute amount (of type Int32).

I added a derived attribute expensesCount (of type Int16) on the user to count the number of expenses, using the derivation expenses.@count. It's working fine, the app compiles, launches, and when I save a relationship, the value for the expensesCount attribute is updated.

I also added a derived attribute expensesAmount on the user to count the total amount of all related expenses. I use the derivation expenses.amount.@sum. The app compiles but crash at launch with the following error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'currently unsupported (unsupported function on to many (not count or sum))'

Any idea why?

PS: I also tried another syntax recommended on Twitter sum:(expenses.amount), but I got the same crash: https://twitter.com/numist/status/1181686971892031488?s=21

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
alpennec
  • 1,864
  • 3
  • 18
  • 25
  • I tried a test project with the same relationships and derived attributes, and it works. I'm not sure why it wouldn't work for you-- maybe something with the version of iOS you're running the code on? I'm trying it with iOS 14.0. Or maybe something with the attribute type for `amount`? I tried `Double`. – Tom Harrington Nov 09 '20 at 17:46
  • Thanks @Tom. I'm running iOS 14.2 & using Xcode 12.2. Here is an example project I sent to Apple Feedback Assistant: https://gofile.io/d/5U2Caj. From my understanding, it's only possible to use the ```@sum``` function for one to many relationships, and not many to many. In my example project, you'll see that the derived attribute is using a many to many relationship. Let me know if you reproduce the bug on your side (can be a bug, a feature improvement, a bad error message...). – alpennec Nov 09 '20 at 18:30
  • I see. From your question it sounded like you had a one-to-many relationship, not many-to-many. That seems to be the reason, unfortunately. If you can't switch to one-to-many then you're probably out of luck with this technique until Apple fixes the framework. – Tom Harrington Nov 09 '20 at 21:35
  • When I asked the question, I was not able to have the @sum function work at all. I tried various things until it worked, and I discovered it was probably due to the type of relationship involved. It’s still an hypothesis but I hope the Apple feedback will be checked. – alpennec Nov 10 '20 at 00:38

0 Answers0