Skip to content

Instantly share code, notes, and snippets.

View eugenezuban's full-sized avatar

Eugene Zuban eugenezuban

View GitHub Profile
eugenezuban / HapticFeedback.swift
Created January 7, 2022 13:43
Haptic Feedback Vibrations in SwiftUI
import SwiftUI
// MARK: - Haptic Feedback Vibrations
enum HapticType {
case light
case medium
case heavy
case success
case error
eugenezuban / CheckDaysStreak.swift
Created April 13, 2021 10:01
A function to help you get the longest contiguous sequence of days from an array of dates. For example, can be used in the habit tracker.
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 = { (date) -> Int in
Calendar.current.dateComponents([.day], from: referenceDate, to: date).day!