Skip to content

Instantly share code, notes, and snippets.

@casperzandbergenyaacomm
casperzandbergenyaacomm / ArrowImageGenerator.swift
Last active Nov 13, 2018 — forked from ale84/ArrowImageGenerator.swift
Helper class to generate simple arrows images of desired size, colour and direction using UIKit api.
View ArrowImageGenerator.swift
//
// ArrowImageGenerator.swift
//
// Created by Alessio Orlando on 07/10/15.
// Copyright © 2015 Alessio Orlando. All rights reserved.
//
import Foundation
import UIKit
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)
@casperzandbergenyaacomm
casperzandbergenyaacomm / DictionaryKeyPath.swift
Last active Jun 14, 2021 — forked from dfrib/DictionaryKeyPath.swift
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
extension Dictionary {
subscript(keyPath string: String) -> Value? {
get {
return self[keyPath: Dictionary.keyPath(for: string)]
}
set {
self[keyPath: Dictionary.keyPath(for: string)] = newValue
@casperzandbergenyaacomm
casperzandbergenyaacomm / EmptyOrNil.swift
Last active Nov 12, 2021
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
}
}
@casperzandbergenyaacomm
casperzandbergenyaacomm / ime-test.swift
Last active May 11, 2018
Implicit Member Expression, Global Constants, and categories Swift
View ime-test.swift
// I wanted to use IME with my global constants (https://medium.com/@maxcampolo/fun-with-global-constants-in-swift-3e012aaec0c7)
// but not lose the functionality of catogories in my constants
// Problem:
extension String {
static let string1 = "Test string."
}
let a: String = String.string1