This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ArrowImageGenerator.swift | |
// | |
// Created by Alessio Orlando on 07/10/15. | |
// Copyright © 2015 Alessio Orlando. All rights reserved. | |
// | |
import Foundation | |
import UIKit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol EmptyOrNil { | |
var isEmpty: Bool { get } | |
} | |
extension Optional where Wrapped: EmptyOrNil { | |
var isEmptyOrNil: Bool { | |
return self?.isEmpty ?? true | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |