Reputation: 61
I have an NSDate attribute called startDate stored in the persistence store in string format like "2020-01-01T23:59:26+0530". I am trying to fetch all the data from the core data which falls before this date. But in my predicate I am not understanding how to form a format string. If the startDate was in Date format, then it would be something like below, let predicate = NSPredicate(format: "date < %@", startDate) But my "date" is not Date instead its a string. I'm not sure how to convert the stored date in string format to just Date format only and apply that in Predicates for comparison. Any suggestions?
Upvotes: 0
Views: 401
Reputation: 232
If you need the time information as well when storing, then it is better to store it as a Date in CoreData because it is very hard and unnecessary coding to compare these.
If you only need date information, then when storing it to CoreData save it with only Date and compare it like this Comparing date string with NSPredicate
Upvotes: 1