Skip to content

Instantly share code, notes, and snippets.

@alejoberman
alejoberman / locking.swift
Created May 19, 2017 08:27 — forked from einsteinx2/locking.swift
Simple synchronization functions for Swift, wrapping the Cocoa NSLocking classes
import Foundation
/// Protocol for NSLocking objects that also provide try()
public protocol TryLockable: NSLocking {
func `try`() -> Bool
}
// These Cocoa classes have tryLock()
extension NSLock: TryLockable {}
extension NSRecursiveLock: TryLockable {}