Coredata:在谓词和比较中将NSString列转换为NSDate [英] Coredata: Convert NSString column to NSDate in predicate and Compare
问题描述
您好我正在开发一个IOS应用程序。其中日期以String列的形式存储在核心数据实体中。现在我想根据日期得到一些过滤的记录。但是问题是日期被保存为String而不是coredata中的NSDate对象。
Hi I am developing an IOS application. In which the dates are stored in String column type in core data entity. Now I want to get some filtered records based on date. But the problem is that the date is saved as String not as NSDate object in coredata.
我的问题是有一种方法来转换Nsdate中的字符串, NSDate对象并获取更大和更小的日期。我想在MYSQL查询中使用MySQL的DATE()函数,并将字符串转换为Date并与任何日期进行比较。
My Question is that is there a way to convert String in Nsdate and compare it with the NSDate object and get the greater and smaller dates. I want something like in MYSQL query where you can use "DATE()" function of MySQL and convert a String to Date and compare it with any date.
推荐答案
我想你可以通过在你的NSManagedObject子类创建一个类别,并创建一个函数,可以将你的nsstring日期转换为nsdate。然后你可以在NSPredicate中比较。
i think you can by creating a category on your NSManagedObject subclass and create a function that can convert your nsstring date into a nsdate . Then you could compare that in an NSPredicate.
这篇关于Coredata:在谓词和比较中将NSString列转换为NSDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!