Average as a fetched property?
I'm not sure if I've understood Fetched Properties c开发者_开发百科orrectly, 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
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.
精彩评论