作为获取的财产平均吗?
我不确定我是否正确理解了获取的属性,所以请告诉我我是否走错了路,而应该做其他事情。
我有一个小演示应用程序,其中有正在审阅的书籍。 Review 实体具有一个分数属性,其 Int16 从 1 到 5 以及一个时间戳,而 Book 实体通过 isReviewed 属性具有零到多条评论(bookInReview 作为其逆属性)。
我想在书上获取一个过去 30 天的平均评论分数。我可以在 Xcode 4 的模型中使用获取的属性来执行此操作吗?如果是这样,怎么办?我可以尝试将 Destination 设置为 Review 并将谓词设置为 @avg(score) 以从所有评论开始,但这似乎不对。
干杯
尼克
I'm not sure if I've understood Fetched Properties correctly, so do tell me if I'm going the wrong way with this and should be doing something else instead.
I have a little demo app where I have books that are being reviewed. A Review entity has a score property with the Int16 from 1 to 5 and a timestamp, and the Book entity has zero-to-many reviews through the isReviewed property (bookInReview as its inverse property).
I want to make a fetched property on book that is an average review score from the past 30 days. Can I use fetched properties in my model in Xcode 4 to do this? If so, how? I can tried setting Destination to Review and predicate to @avg(score) to start with all the reviews but that doesn't seem right.
Cheers
Nik
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
获取的属性返回 NSManagedObjects 的 NSArray(实际上是 _NSFaultingArray 或类似的东西),因此我不认为可以获取像 @sum、@average 或 @count 这样的聚合作为获取的属性。但是,这并不意味着您不能将它们添加到 NSManagedObject 的子类或类别中。
Fetched Properties return an NSArray (actually an _NSFaultingArray, or something like that) of NSManagedObjects, so I don't believe it is possible to fetch aggregates like @sum, @average, or @count as fetched properties. However, that doesn't mean you cannot add them to a subclass of NSManagedObject or a category.