Realm date-query

℡╲_俬逩灬. 提交于 2019-12-04 04:19:40
SpencerBaker

You can query Realm with dates.

If you want to get objects after a date, use greater-than (>), for dates before, use less-than (<).

Using a predicate with a specific NSDate object will do what you want:

let realm = Realm()    
let predicate = NSPredicate(format: "date > %@", specificNSDate)
let results = realm.objects(NameEntry).filter(predicate)

Question 1: For the number of objects, just call count: results.count

Question 2: results is an array of NameEntrys after specificNSDate, get the object at indexPath. Example, let nameEntry = results[indexPath.row]

For creating a specific NSDate object, try this answer: How do I create an NSDate for a specific date?

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