Skip to content

Instantly share code, notes, and snippets.

@camcaine
camcaine / TabSelect.swift
Last active February 25, 2021 08:18
Managing TabView selections in SwiftUI
import SwiftUI
protocol TabSelectable {
associatedtype Tab
func shouldSelect(_ tab: Tab) -> Bool
}
@propertyWrapper
struct TabSelection<Value: Hashable> {
@camcaine
camcaine / gist:769402
Created January 7, 2011 12:12
Calculate Age
def age
now = Time.now.utc.to_date
gap = (now.month > dob.month ||
(now.month == dob.month && now.day >= dob.day)) ? 0 : 1
now.year - dob.year - gap
end