I need to quickly produce some functions which will allow me to store and retrieve some date ranges. Then evaluate the dates based on todays date, then add them to an array.
I’m not exactly sure how many ranges I’ll need to keep.
Perhaps you’ve seen a similar example of this I can use for reference?
EDIT.
I need to save them for use when the app is next run too.
You can represent a date range in two ways:
You can then represent a date as an NSDate instance, as a double (or, if you desperately need to save memory, as an int, like UNIX timestamp). I’d make a class for that.
The bonus point is that you can store as many ranges in Cocoa collections (such as NSArray) as needed. I leave a better implementation of
-isEqual:and-hashas an exercise to you, dear reader.To save a DateRange object in NSUserDefaults:
To read a DateRange object from NSUserDefaults:
Similarly, if you need to store an NSArray of DateRanges, you can either archive the whole array or create an array of archived DateRanges (the former should be faster):
If you think that’s too much repetitive code for your project, you can extend NSUserDefaults like this: