Search code examples
ioscore-datansfetchrequesttype-conversionnsdatecomponents

How do I store the time part of NSDateComponents?


I want to store times type value (but not the date) in Core Data. Which data type should I use?


Solution

  • Possible options:

    • Three integer attributes for hour, minutes, seconds.
    • One string attribute for "HH:MM:SS".
    • One integer attribute for the number of seconds since midnight.

    The best representation depends on what type of queries involving the time you want to execute. The first option is better if you want to search for a given hour, minute or second. The other options are better if you have to search for time intervals.