I need to count last streak of days, but can't figure out how to do this. For example I got core data like this:
|id| isPresent(Bool)| date(NSDate)|
|==|================|=============|
| 1| 0| 2016-02-11 |
| 2| 1| 2016-02-11 |
| 3| 1| 2016-02-12 |
| 4| 0| 2016-02-14 |
| 5| 1| 2016-02-15 |
| 6| 1| 2016-02-16 |
| 7| 1| 2016-02-16 |
I try to check last not presented(isPresent = 0) date till today and get 2016-02-14 - so I can count days, it is easy.
But if I mark 2016-02-14 as isPresented = 1(like in table lower) I will get last not presented 2016-02-11 - but it is not correct there are no data for 2016-02-13, so isPresented for this date should be 0 and streak should count from this date
|id| isPresent(Bool)| date(NSDate)|
|==|================|=============|
| 1| 0| 2016-02-11 |
| 2| 1| 2016-02-11 |
| 3| 1| 2016-02-12 |
| 4| 1| 2016-02-14 |
| 5| 1| 2016-02-15 |
| 6| 1| 2016-02-16 |
| 7| 1| 2016-02-16 |
I searched for different algoritm for streaks or sql reuests for missing dates(sql server displaying missing dates) but cant figure out how to use it in core data.
I thinking about another data that will keep streak and updates every time when user opened app, but got same problem what if user didn't open app.
Output: I need to found just counts of days in streak or date when it break, so for
For first table: streak = 2 or breakDate = 2016-02-14 - I try this, but my solution wrong because second table
For second table: streak = 3 or breakDate = 2016-02-13 - can't figure out how to get missing date
Important Update: There will be cloud sync data, so I don't see any solution inside app, really need to find missing date or isPresented = 0 in coredata
p.s. I'm using swift if you can help me via swift it would be great, but I also understand Obj-C. And sorry for my bad English