Search code examples
objective-ccore-dataios7nspredicatemagicalrecord-2.2

Using NSPredicate, how to get quarterly results from CoreData?


I need to get quarterly results of the records in my CoreData store. The question is how do I compare the stored NSDate month to determine which quarter it belongs to?


Solution

  • Denormalize your data, have a quarter or a month property, and use that.

    Database normalization means removing redundant information. However, sometimes, especially in Core Data, you want to add additional data to save computations.

    For example in your case, upon insertion and update of your objects, calculate the quarter they belong to. Now, when you want to fetch the information, a very simple query will return the data.