getting the sum of all instances of Entity B from a given instance of Entity A

孤街浪徒 提交于 2019-12-10 23:32:34

问题


I have a to-many relationship between Entity A and Entity B (iOS Core Data app). I need to get the sum of the NSDecimalNumber attribute of all instances of Entity B from a given instance of Entity A. Does anyone have a tutorial or example of this?


回答1:


You would use the @sum collection operator thusly:

NSNumber *theSum=[ObjectA.objectBs valueForKey:@"@sum.numericalAttribute"];


来源:https://stackoverflow.com/questions/5251255/getting-the-sum-of-all-instances-of-entity-b-from-a-given-instance-of-entity-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!