Skip to content

Instantly share code, notes, and snippets.

View pushpankq's full-sized avatar
🏠
Working from home

Pushpank pushpankq

🏠
Working from home
  • Noida
View GitHub Profile
class ThreadSafeDictionary<Key: Hashable, Value> {
private var dictionary: [Key: Value] = [:]
private let concurrentQueue = DispatchQueue(label: "com.concurrentQueue")
func setValue(_ value: Value, key: Key) {
concurrentQueue.async(flags: .barrier) {
self.dictionary[key] = value
}
}