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
// | |
// Weak.swift | |
// | |
// Created by Steffan Andrews on 2019-11-16. | |
// Copyright © 2019 Steffan Andrews. All rights reserved. | |
// | |
// MARK: - Weak<T> | |
/// Wrapper that contains a weak reference to an object. |
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 Result { | |
@_disfavoredOverload | |
public mutating func set(_ newSuccess: Success) { | |
self = .success(newSuccess) | |
} | |
@_disfavoredOverload | |
public mutating func set(_ newFailure: Failure) { | |
self = .failure(newFailure) | |
} |
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 | |
// MARK: - App Icons | |
func getIcon(file path: String) -> NSImage? { | |
guard FileManager.default.fileExists(atPath: path) | |
else { return nil } | |
return NSWorkspace.shared.icon(forFile: path) | |
} |
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
infix operator ?|: NilCoalescingPrecedence | |
extension Collection { | |
/** Elvis Operator (`?:` or `||` in other languages) | |
Works on String, Array, Collection, Set, etc. | |
Returns the left-hand value if it is not empty. | |
"" ?| "Default" // "Default" | |
"String" ?| "Default" // "String" | |
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
#if os(macOS) | |
import Foundation | |
/// On init, parses Dropbox's info.json file and populates the pertinent data into variables. Object is nil if info.json file can't be found (which usually means Dropbox is not installed on the system) or there was a generic error parsing the JSON data. | |
/// | |
/// Properties are populated once upon the struct's init. There is no method to refresh the data. Instead, instance a new copy of `DropboxPaths`. | |
/// | |
/// - `personalPath`: POSIX path if found; nil if not discoverable | |
/// - `personalURL`: URL if found; nil if not discoverable |
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 | |
/// Returns an array of random numbers. Values will be beween the range given, with an array size of `count`. | |
/// | |
/// Example: | |
/// ``` | |
/// [UInt8](randomValuesBetween: 0...255, count: 4) // [4,75,241,176] | |
/// ``` | |
extension Array where Element : FixedWidthInteger { | |
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
/// Wraps a value with a DispatchSemaphore(value: 1) to prevent overlapping access. | |
@propertyWrapper public struct Semaphored<T> { | |
private var value: T | |
private var semaphore = DispatchSemaphore(value: 1) | |
public var wrappedValue: T { | |
get { | |
defer { semaphore.signal() } | |
semaphore.wait() |