I’d like to create a simple pills reminder iOS application (let’s leave notifications aside for the moment).
I want to create a single DB record for a pill that has repetitions and check if a specific day intersects date “generated” by the repetition.
Example:
I set a pills period that starts from April 12 and ends April 20, with repetition every 2 days , at 3.00 pm.
So this pills is valid for this dates :
- April 12 at 3.00pm
- April 14 at 3.00pm
- April 16 at 3.00pm
- April 18 at 3.00pm
- April 20 at 3.00pm
Questions:
-
Which type of data can describe the information “Every 2 days”? NSDateInterval would be a good solution ?
-
How can i verify that a specific day agrees with my repetition scheme ? (i.e. Check if April 13 is a valid date for the previous example and get “NO” as answer)
Here is an example class which should meet your criteria:
main.m
DateChecker.h
DateChecker.m
That should give you an idea on how to write a class that can handle your requirements. I ran this as a command line app and it seemed to work alright. The function
was graciously obtained from How to Check if an NSDate occurs between two other NSDates.