iOS 5 - Core Data TableView Sections based on NSDate Ranges

Discussion in 'iOS Programming' started by mdhansen5, Jun 12, 2012.

  1. mdhansen5 macrumors member

    Nov 22, 2010
    I'd like to be able to create a UITableView using Core Data and NSFetched results controller that is divided up into a number of sections, each based on a range of dates, for example: within 5 days, within 10 days and within 20+ days, or something like that. I would be using an NSDate Core Data attribute called "date." I know how to divide the tableview into sections based off of each single date item, but not how to organize it like this. Can anyone help out with this? All I need is a bit of starting point.

    Thanks a bunch everyone! I'm pretty new to iOS development, so please bear with me. :)
  2. MattInOz macrumors 68030


    Jan 19, 2006
    Have a look at Core Data Transient Properties.

    Which are only stored in memory not in the database file. Core data has some tricks to keep it's memory use pretty neat, as an object gets pulled out of data base in to memory you a chance to fill in the transient properties. If your using a 5day range then you have a big tolerance if the object stays in memory for a while.

    A transient property can be used by NSFetchedResults as the sectionKeyPathName.

    So you could take your NSDate that you have stored do some math to it to work out which 5 day range it's in and store that as a transient property. All the Entities with same value in that property will then be in the same table section.

Share This Page