This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
// MARK: - Haptic Feedback Vibrations | |
enum HapticType { | |
case light | |
case medium | |
case heavy | |
case success | |
case error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func checkStreak(of dateArray: [Date]) -> Int{ | |
let dates = dateArray.sorted() | |
// Check if the array contains more than 0 dates, otherwise return 0 | |
guard dates.count > 0 else { return 0 } | |
// Get full day value of first date in array | |
let referenceDate = Calendar.current.startOfDay(for: dates.first!) | |
// Get an array of (non-decreasing) integers | |
let dayDiffs = dates.map { (date) -> Int in | |
Calendar.current.dateComponents([.day], from: referenceDate, to: date).day! | |
} |