我到处都看了,甚至访问了一些可疑的网站,这些网站的病毒警告消息永远不会消失,但我无法弄清楚这一点。
我只是想过滤 Results<T>
按日期对象:
let messages = realm.objects(RMChatMessage).filter("timestamp > \(date)) AND (timestamp <= \(to))"))
每当运行此行时,它都会引发以下内容:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "timestamp > 1970-01-01 00:00:00 +0000"'
*** First throw call stack:
(
0 CoreFoundation 0x000000010fba8c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000011174ebb7 objc_exception_throw + 45
2 Foundation 0x000000010ffb66bd _qfqp2_performParsing + 8495
3 Foundation 0x000000010ffb4526 +[NSPredicate predicateWithFormat:arguments:] + 46
...
我尝试使用 NSDateFormatter
格式如 yyyy-MM-dd hh:mm:ss
, 或 date.description
, 使用 NSPredicate(format:...)
而不是 Result<T>.filter(...)
, 等等,但没有任何效果。
这是 Realm 中的一些错误吗?
最佳答案
let messages = realm.objects(RMChatMessage).filter("timestamp > %@ AND timestamp <= %@", date, to)
NSPredicate
对 Swift 字符串插值没有任何特殊处理,也不支持直接在格式字符串中写入日期。
关于ios - 通过 NSDate 在 Realm 中过滤查询抛出 NSInvalidArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31952669/