This file contains 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
// | |
// NSStackView+Animations.swift | |
// | |
// Created by Martin Höller on 18.06.16. | |
// Copyright © 2016 blue banana software. All rights reserved. | |
// | |
// Based on http://prod.lists.apple.com/archives/cocoa-dev/2015/Jan/msg00314.html | |
import Cocoa |
This file contains 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
extension URL { | |
// Inserts a timestamp into a URL's filename | |
// e.g. "/path/to/file.ext" -> "/path/to/file~1587197384.ext" | |
func addingTimestamp(separator: String = "~") -> URL { | |
let timestamp = Int(Date().timeIntervalSince1970) | |
let filename = deletingPathExtension().lastPathComponent + "\(separator)\(timestamp).\(pathExtension)" | |
return deletingLastPathComponent().appendingPathComponent(filename) | |
} | |
} |
This file contains 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 AppKit | |
// based on https://www.hackingwithswift.com/example-code/strings/how-to-detect-a-url-in-a-string-using-nsdatadetector | |
// and https://stackoverflow.com/a/14604456/379776 | |
class LinkDetectingTextView: NSTextView { | |
override var string: String { | |
didSet { | |
highlightLinks() | |
} | |
} |
This file contains 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://stackoverflow.com/a/49205781/379776 and https://swiftbysundell.com/articles/property-wrappers-in-swift/ | |
import UIKit | |
/* | |
Add something like this to your podspec | |
s.resource_bundles = { | |
'Assets' => ['MyPod/Assets/**/*.{xcassets}'] | |
} |
This file contains 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 CoreLocation | |
/** | |
A bounding box implementation that can be initialized either with NE/SE or with an array of coordinates. | |
*/ | |
struct BoundingBox { | |
let ne: CLLocationCoordinate2D | |
let sw: CLLocationCoordinate2D | |
let center: CLLocationCoordinate2D | |
let latitudeSpread: CLLocationDegrees |
This file contains 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 KeyedDecodingContainerProtocol { | |
/** | |
Decodes a value of the given type for the given key, providing a default value if the value could not be decoded. | |
- parameter type: The type of value to decode. | |
- parameter key: The key that the decoded value is associated with. | |
- parameter defaultValue: The default value that is used if the a value for `key` could not be decoded. |
This file contains 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
/** | |
Decodes a value of the given type for the given key, providing a transform closure that converts the decoded value into another type. | |
- parameter type: The type of value to decode. | |
- parameter key: The key that the decoded value is associated with. | |
- parameter transform: A closure that transforms the decoded value into a value of a different type. | |
- returns: The value that was returned by the `transform` closure. | |
*/ | |
func decode<T, R>(_ type: T.Type, forKey key: Self.Key, transform: (T) throws -> R) throws -> R where T : Decodable { |
This file contains 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 Array where Element: Hashable { | |
/** | |
Returns a new array containing only the unique elements of the receiver. | |
- warning: There are no guarantees about the order of the returned array. | |
*/ | |
var uniqued: Self { Array(Set(self)) } | |
} |
This file contains 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 Cocoa | |
import Foundation | |
var colors: [NSColor] = [.labelColor, .secondaryLabelColor, .tertiaryLabelColor, .quaternaryLabelColor, .textColor, .placeholderTextColor, .selectedTextColor, .textBackgroundColor, .selectedTextBackgroundColor, .keyboardFocusIndicatorColor, .unemphasizedSelectedTextColor, .unemphasizedSelectedTextBackgroundColor, .linkColor, .separatorColor, .selectedContentBackgroundColor, .unemphasizedSelectedContentBackgroundColor, .selectedMenuItemTextColor, .gridColor, .headerTextColor, .controlAccentColor, .controlColor, .controlBackgroundColor, .controlTextColor, .disabledControlTextColor, .selectedControlColor, .selectedControlTextColor, .alternateSelectedControlTextColor, .windowBackgroundColor, .windowFrameTextColor, .underPageBackgroundColor, .findHighlightColor, .highlightColor, .shadowColor | |
] | |
for color in colors { | |
var red: CGFloat = 0 | |
var green: CGFloat = 0 | |
var blue: CGFloat = 0 |