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
private extension NSImage { | |
static func checkerboardImage(ofSize: CGSize, color1: NSColor, color2: NSColor, checkSize: CGFloat = 8) -> NSImage? { | |
let width = NSNumber(value: Float(checkSize)) | |
let center = CIVector(cgPoint: CGPoint(x: 0, y: 0)) | |
let darkColor = CIColor(cgColor: color1.cgColor) | |
let lightColor = CIColor(cgColor: color2.cgColor) | |
let sharpness = NSNumber(value: 1.0) | |
guard let filter = CIFilter(name: "CICheckerboardGenerator") else { | |
return nil |
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
/// A simple layer class to expose an animation progress for a CAAnimation. | |
public class ArbitraryAnimationLayer: CALayer { | |
static let KeyPath: String = "progress" | |
override init() { | |
super.init() | |
} | |
var progressCallback: ((CGFloat) -> Void)? |
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
// FROM: https://www.objc.io/blog/2018/12/18/atomic-variables/ | |
final class Atomic<A> { | |
private let queue = DispatchQueue(label: "Atomic serial queue") | |
private var _value: A | |
init(_ value: A) { | |
self._value = value | |
} | |
var value: A { |
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
// | |
// DSFRestrictedPanGestureRecognizer.swift | |
// Time Zones | |
// | |
// Created by Darren Ford on 30/6/18. | |
// Copyright © 2018 Darren Ford. All rights reserved. | |
// | |
import UIKit | |
import UIKit.UIGestureRecognizerSubclass |
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 String { | |
/// Returns a new string by removing any instances of the specified characters | |
/// | |
/// - Parameter | |
/// - replacementChars: String containing the characters to replace | |
/// - Returns: a new string filtering out the specified characters | |
func removing(charactersIn replacementChars: String) -> String { | |
return self.filter { replacementChars.contains($0) == false } |
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 | |
class AutoselectOnFocusTextField: NSTextField { | |
override func becomeFirstResponder() -> Bool { | |
guard super.becomeFirstResponder() else { | |
return false | |
} | |
if let editor = self.currentEditor() { | |
editor.perform(#selector(selectAll(_:)), with: self, afterDelay: 0) | |
} |
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
let menuController = UIMenuController.shared | |
let item1 = UIMenuItem(title: "Item 1", action: #selector(performItem1)) | |
let item2 = UIMenuItem(title: "Item 2", action: #selector(performItem2)) | |
menuController.menuItems = [item1, item2] | |
menuController.setMenuVisible(true, animated: true) |
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 UIKit | |
extension UIColor { | |
private struct ColorComponents { | |
var r: CGFloat = 0.0 | |
var g: CGFloat = 0.0 | |
var b: CGFloat = 0.0 | |
var a: CGFloat = 0.0 | |
} |
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
/// From https://www.rightpoint.com/rplabs/xctassert-optional-unwrapping | |
// Usage :- | |
// | |
// class TestCaseUnwrap: XCTestCase { | |
// func testUnwrap() throws { | |
// let string: String? = nil | |
// let newString = try AssertNotNilAndUnwrap(string) | |
// XCTAssert(newString.lengthOfBytes(using: .utf8) > 0) | |
// } |
OlderNewer