【发布时间】:2015-03-13 18:21:59
【问题描述】:
当我在 iPhone 应用程序中从 Core 数据数据库中获取数据时遇到问题。
我正在使用此代码(第 1 行),它工作正常,这里我正在从日期获取数据:
注意:date的数据类型是NSDate,selectedDate也是NSDate的类型。
第一行:
[NSPredicate predicateWithFormat:@"date == %@",selectedDate];
这段代码 (第 2 行) 在我获取系统数据时也可以正常工作:
第 2 行:
[NSPredicate predicateWithFormat:[NSString stringWithFormat:@"systemName == '%@'",selectedSystemString]];
但是当我将上述两个谓词与这段代码结合起来时 (第 3 行):
第 3 行:
[NSPredicate predicateWithFormat:[NSString stringWithFormat:@"(date == %@) AND (systemName == '%@')",selectedDate,selectedSystemString]];
应用程序在第 3 行崩溃,控制台中显示此错误消息:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "(date == 2015-01-15 18:30:00 +0000) AND (systemName == 'A')"'
*** First throw call stack:
(0x26494c1f 0x33c9cc8b 0x270feb55 0x270fc9bd 0x270fc93d 0x9b263 0x9c143 0xa8815 0x29a69f97 0x29b1bc0f 0x299cdc4d 0x29949aab 0x2645b3b5 0x26458a73 0x26458e7b 0x263a7211 0x263a7023 0x2d75a0a9 0x299b31d1 0xb1e7d 0x3421caaf)
libc++abi.dylib: terminating with uncaught exception of type NSException
【问题讨论】:
-
使用
(systemName == %@) -
感谢@flexaddicted 的评论。我已经使用了这段代码(systemName == %@)但仍然崩溃。 :(
-
你收到同样的错误吗?
-
是,*** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“无法解析格式字符串”(日期 == 2015-01-15 18:30:00 +0000) AND (systemName == A)"'
-
你在用这个吗?
[NSPredicate predicateWithFormat:@"date == %@ AND systemName == %@",selectedDate,selectedSystemString];
标签: ios objective-c core-data nsdate nspredicate