考虑到我有一个对象,如下所示:
class SleepStatistics : Object {
dynamic var onBedTimeStart:NSDate?;
dynamic var onSleepTimeEnd:NSDate?;
}
我每天都有几条记录,我想在下午5点到晚上11点之间只过滤记录,而不管日期。谁能指导我怎么做?
答案 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)