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
@objc class CIImageToNSImageTransformer: ValueTransformer { | |
@objc public static func RegisterTransformer() { | |
ValueTransformer.setValueTransformer( | |
CIImageToNSImageTransformer(), | |
forName: NSValueTransformerName("CIImageToNSImageTransformer") | |
) | |
} | |
override class func transformedValueClass() -> AnyClass { | |
return NSImage.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
@objc class DataToStringReversableTransformer: ValueTransformer { | |
static func RegisterTransformer() { | |
ValueTransformer.setValueTransformer( | |
DataToStringReversableTransformer(encoding: .utf8), | |
forName: NSValueTransformerName("DataToStringReversableTransformer_utf8") | |
) | |
ValueTransformer.setValueTransformer( | |
DataToStringReversableTransformer(encoding: .utf16), | |
forName: NSValueTransformerName("DataToStringReversableTransformer_utf16") | |
) |
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
// | |
// Clamp.swift | |
// | |
// Created by Darren Ford on 6/7/20. | |
// Copyright © 2020 Darren Ford. All rights reserved. | |
// | |
import Foundation | |
public extension ExpressibleByIntegerLiteral where Self: FloatingPoint { |
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
class MarchingAntsSelectionLayer: CAShapeLayer { | |
func setup() { | |
let dashPattern: [NSNumber] = [2.0, 2.0] | |
let dashPhase = dashPattern.map { $0.floatValue }.reduce(0) { $0 + $1 } | |
self.lineDashPattern = dashPattern | |
let lineDashPhaseAnimation = CABasicAnimation(keyPath: "lineDashPhase") | |
lineDashPhaseAnimation.byValue = dashPhase | |
lineDashPhaseAnimation.duration = 0.5 |
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
extension NSImage { | |
/// An NSImage extension that converts an NSImage in ANY format to a new NSImage using the calibrated RGB colorspace. | |
/// | |
/// Useful when you have to support a 3rd party tool that has format limitations, such as not supporting | |
/// paletted PNG files or grayscale colorspaces (I'm looking at you Create ML!) | |
func copyAsCalibratedRGBColorspace() -> NSImage? { | |
guard let rep = self.representations.first else { | |
return nil | |
} |
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
// | |
// String+extensions.swift | |
// | |
// Created by Darren Ford on 6/4/20. | |
// | |
// Lazy extensions for Swift Strings indexing | |
// | |
// For example :- | |
// let value = "Caterpillar" | |
// let catStr = value.substring(0 ..< 3) |
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
/// Stream generic functions for NSView and NSCell to allow quick initialisation of properties | |
/// Useful for when your (eg) button variable has a long name or is optional. | |
func <<<T> (left: T, configureBlock: (T) -> Void) -> T where T: NSView { | |
configureBlock(left) | |
return left | |
} | |
func <<<T> (left: T, configureBlock: (T) -> Void) -> T where T: NSCell { | |
configureBlock(left) | |
return left |
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
extension NSControl.StateValue: CustomStringConvertible { | |
public var description: String { | |
switch self { | |
case .on: return NSLocalizedString("On", comment: "State for when a control is 'on'") | |
case .mixed: return NSLocalizedString("Mixed", comment: "State for when a control is neither on of off") | |
case .off: return NSLocalizedString("Off", comment: "State for when a control is 'off'") | |
default: fatalError("unimplemented state") | |
} | |
} | |
} |
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
extension NSColor { | |
private struct ColorComponents { | |
var r: CGFloat = 0.0 | |
var g: CGFloat = 0.0 | |
var b: CGFloat = 0.0 | |
var a: CGFloat = 0.0 | |
} | |
private func components() -> ColorComponents { | |
var result = ColorComponents() |
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 String { | |
/// Retrieve the contents of the string as a Bool value. | |
/// | |
/// This property is true on encountering one of "Y", "y", "T", "t", or a digit 1-9—the method ignores any trailing characters. This property is false if the receiver doesn’t begin with a valid decimal text representation of a number. | |
/// | |
/// The property assumes a decimal representation and skips whitespace at the beginning of the string. It also skips initial whitespace characters, or optional -/+ sign followed by zeroes. | |
/// | |
/// See: [NSString boolValue](https://developer.apple.com/documentation/foundation/nsstring/1409420-boolvalue) |