Cannot use a predicate that compares dates in Magical Record

前端 未结 2 1422
小鲜肉
小鲜肉 2020-12-12 02:53

I am making a method that will remove all of my NSManagedObjects that were not updated in the last sync.

- (void)removeStaleObjects {

        // Delete obje         


        
相关标签:
2条回答
  • 2020-12-12 03:12

    The problem is the name "updated" of your attribute. It conflicts with the isUpdated method of NSManagedObject. (See Core Data NSPredicate "deleted == NO" does not work as expected for a similar issue with a "deleted" attribute.)

    If you rename your attribute, everything works as expected.

    0 讨论(0)
  • 2020-12-12 03:27

    It also looks to my that your predicate is formatted correctly. Here are a couple things you can do:

    1) When debugging this, print out that predicate. You should see something like:

    updatedDate < {some integer value}
    

    Dates are stored as integers under the covers, and a predicate converts it properly as well. If your predicate isn't printable in the debugger, you'll know right away

    2) Check your updatedDate type. Make sure that's a date (I trust it's already a date, but you didn't specify in your question)

    3) Make sure your Node object has the updatedDate attribute on it.

    0 讨论(0)
提交回复
热议问题