Skip to content

Instantly share code, notes, and snippets.

View gahms's full-sized avatar

Nicolai Henriksen gahms

View GitHub Profile
// Instead of this
Picker(selection: $viewModel.monthViewHideAction) {
ForEach(FilterDecorationHideAction.allCases, id: \.rawValue) { p in
Text(p.localized).tag(p)
}
} label: {
Text("Event text")
}
// I use this
@gahms
gahms / dart-date-format-example.dart
Last active March 14, 2024 12:37
DartPad date format example
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
void main() async {
await initializeDateFormatting();
final dt = DateTime.now();
print(DateFormat.yMd('en_UK').format(dt));
print(DateFormat.yMd('da_DK').format(dt));
print(DateFormat('dd.MM.yyyy').format(dt));
@gahms
gahms / Persistent.swift
Last active May 9, 2022 17:45
Swift UserDefaults packaging
import Foundation
final class Persistent {
static let standard: Persistent = .init()
private var store: UserDefaults = UserDefaults.standard
private lazy var jsonEncoder: JSONEncoder = JSONEncoder()
private lazy var jsonDecoder: JSONDecoder = JSONDecoder()
func reset() {
// ref: https://stackoverflow.com/a/43402290/833197