iOS:如何使用谓词NSexpression检查用户input的有效性和一致性

在我的应用程序使用coredata我有一个实体具有两个属性GridValue (数值), RecordingDate (NSdate))。 一个tableview中的用户可以每天input这两个值,并用一个获取控制器logging。 这里有更多的理解是关于这个问题的两个观点的截图:

在这里输入图像说明

AddviewController是用户添加新值的地方,当用户点击静态tableview中的两个字段时,他被redirect到“Zahl Datum”视图进行编辑。

我想要做的是检查用户input的GridValue ,并显示一个警告(可能是一个警告消息,或者在这种情况下,当新input的值小于先前input的值时,将显示或popup的页脚消息在不同的日子(以前存储的RecordingDate值(来自CoreData模型的NSdateinput属性))。

示例说明当前用户是否input:Zahlerstand = 1254和Datum: 12,05,2013 ,在之前的logging中,值分别为:Zahlerstand = 1300和Datum: 11.05.2013。 那么我们就会看到,在连续的date里, 新价值比旧价值要小 。 在这种情况下,应该显示警告 (如在tableview部分页脚中,然后才能点击addviewcontroller中的“save”button。

请尽可能帮助一些示例代码。

先谢谢你,

使用NSComparisonResult将旧date与新date进行比较:

compare: method returns an NSComparisonResult value that indicates the temporal ordering of the receiver and another given date. - (NSComparisonResult)compare:(NSDate *)anotherDate switch ([olderDate compare:newDate]) { case NSOrderedAscending: // olderDate is earlier in time than newDate break; case NSOrderedSame: // Both dates are same break; case NSOrderedDescending: // olderDate is later in time than newDate break; }