Skip to content

Instantly share code, notes, and snippets.

View nicodioso's full-sized avatar

Nico Dioso nicodioso

  • Philippines
View GitHub Profile
@nicodioso
nicodioso / Combine2DatesWithSpecifiedComponents.swift
Created January 26, 2022 18:20
Combine two dates specify which components you want to retain from each one
extension Date {
/// Note: Any duplicate found from 2 components will return nil
func combine(_ date1Comp: Set<Calendar.Component>, with date2: Date, components date2Comp: Set<Calendar.Component>) -> Date? {
// Check if has duplicates
let date1CompDict: [Calendar.Component: Bool] = {
var dict: [Calendar.Component: Bool] = [:]
date1Comp.forEach{ dict[$0] = true }