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
// 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
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
let query = MDQueryCreate(kCFAllocatorDefault, "kMDItemContentType = com.apple.application-bundle" as CFString, nil, nil) | |
MDQueryExecute(query, CFOptionFlags(kMDQuerySynchronous.rawValue)) | |
let count = MDQueryGetResultCount(query); | |
for i in 0 ..< count { | |
let rawPtr = MDQueryGetResultAtIndex(query, i) | |
let item = Unmanaged<MDItem>.fromOpaque(rawPtr!).takeUnretainedValue() | |
if let path = MDItemCopyAttribute(item, kMDItemPath) as? String { | |
print(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
// NSWorkspace.accessibilityDisplayOptionsDidChangeNotification fires when option changes. | |
// The only thing is, it fires in NSWorkspace's notification center. Not in the default one. | |
///// Using a selector | |
NSWorkspace.shared.notificationCenter.addObserver( | |
self, | |
selector: #selector(accessibilityDisplayOptionsDidChange(_:)), | |
name: NSWorkspace.accessibilityDisplayOptionsDidChangeNotification, | |
object: NSWorkspace.shared) |
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
// | |
// CAAnimation+BlockCallback.swift | |
// | |
import UIKit | |
// | |
// Modified from http://onedayitwillmake.com/blog/2016/06/caanimation-completion-callback-block/ | |
// Updated for Swift 4 syntax | |
// All credit to the original author (Mario Gonzalez) |
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 UUID { | |
/// Errors thrown | |
public enum LoadError: Error { | |
case invalidUUIDData | |
} | |
/// Returns the raw bytes of the UUID as a Data object. | |
/// | |
/// Note that this method assumes a specific memory layout (the layout on the device calling the method) | |
/// and as such may not be portable to other systems. |
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
extension NSImage { | |
/// Create a CIImage using the best representation available | |
/// | |
/// - Returns: Converted image, or nil | |
func asCIImage() -> CIImage? { | |
if let cgImage = self.asCGImage() { | |
return CIImage(cgImage: cgImage) | |
} | |
return nil | |
} |
OlderNewer