How to calculate streak of days in core data?
<p>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:</p>

<pre><code>|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  |
</code></pre>

<p>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.</p>

<p>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</p>

<pre><code>|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  |
</code></pre>

<p>I searched for different algoritm for streaks or sql reuests for missing dates(<a href="https://stackoverflow.com/questions/22329722/sql-server-displaying-missing-dates">sql server displaying missing dates</a>) but cant figure out how to use it in core data. </p>

<p>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.</p>

<p><strong>Output:</strong>
I need to found just counts of days in streak or date when it break, so for</p>

<p>For first table: streak = 2 or breakDate = 2016-02-14 - I try this, but my solution wrong because second table</p>

<p>For second table: streak = 3 or breakDate = 2016-02-13 - can't figure out how to get missing date</p>

<p><strong>Important Update:</strong>
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>

<p><strong>p.s.</strong> 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</p>