Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀

Casper Zandbergen Amzd

🚀
View GitHub Profile
@Amzd
Amzd / EmptyOrNil.swift
Created Nov 12, 2021 — forked from casperzandbergenyaacomm/EmptyOrNil.swift
Adding readability for an if statement I often use.
View EmptyOrNil.swift
protocol EmptyOrNil {
var isEmpty: Bool { get }
}
extension Optional where Wrapped: EmptyOrNil {
var isEmptyOrNil: Bool {
return self?.isEmpty ?? true
}
}
@Amzd
Amzd / DictionaryKeyPath.swift
Last active Jul 12, 2021 — forked from casperzandbergenyaacomm/DictionaryKeyPath.swift
Reading and writing to (possible) nested dictionaries for a given key path, using a recursive approach
View DictionaryKeyPath.swift
// Inspired by: https://gist.github.com/dfrib/d7419038f7e680d3f268750d63f0dfae
import Foundation
public extension Dictionary {
subscript(keyPath string: Key, separator: String) -> Value? where Key == String {
get { return self[keyPath: string.components(separatedBy: separator)] }
set { self[keyPath: string.components(separatedBy: separator)] = newValue }
}
View DateRounding.swift
import Foundation
extension Date {
/// Returns date where **-component** is rounded to its closest
/// multiple of **-amount**. Warning: month and day start at 1
/// so round(to: 6, .month) will either return month 1 or 7!
func round(to amount: Int, _ component: Calendar.Component) -> Date {
let cal = Calendar.current
var value = cal.component(component, from: self)
@Amzd
Amzd / Instructions.md
Last active Jun 19, 2019 — forked from alloy/Instructions.md
Run iOS unit tests (in a Xcode workspace) when a file changes and *only* those tests related to the changed file. Also trims otest output and colors test results.
View Instructions.md