简体   繁体   中英

CoreData sort by factor of date

I have an iOS app that frequently adds content and saves it in CoreData. Each content item has a fixed score.

I would like to be able to sort these in a similar way to the Hacker News algorithm ( http://amix.dk/blog/post/19574 ). That is, against a calculated attribute based partly on the age of the content, partly on the score of the content; eg (score) / (age in hours)^(1.8)

With plain SQL this is possible, but does CoreData abstract things too much?

You need to create a new property the contains your calculated score.

When you update your object, undated the calculated score as well.

If you want to apply a sort to a fetch request, using the calculated score as a sort key, don't add it as a transient property as these aren't stored in the underlying SQL database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM