Realm Swift:特定时间之间的所有记录

时间:2017-09-21 13:26:33

标签: ios swift realm

考虑到我有一个对象,如下所示:

class SleepStatistics : Object {
  dynamic var onBedTimeStart:NSDate?;
  dynamic var onSleepTimeEnd:NSDate?;
}

我每天都有几条记录,我想在下午5点到晚上11点之间只过滤记录,而不管日期。谁能指导我怎么做?

1 个答案:

答案 0 :(得分:1)

您可以使用Realm Results的函数filter。像这样:

let predicate = NSPredicate(format: "onBedTimeStart >= %@ AND onSleepTimeEnd <= %@", onBedDate as CVarArg, onSleepDate as CVarArg)

let result = realm.objects(YourObject.self).filter(predicate)