Popularity
1.0
Stable
Activity
0.0
Stable
36
2
6
Code Quality Rank:
L5
Programming language: Swift
License: MIT License
Tags:
Thread
Latest version: v1.0.3
Atomic alternatives and similar libraries
Based on the "Thread" category.
Alternatively, view Atomic alternatives based on common mentions on social networks and blogs.
-
Async
Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch -
Schedule
Schedule timing task in Swift using a fluent API. (A friendly alternative to Timer) -
Async.legacy
Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch (iOS7+ and OS X 10.9+ compatible) -
EKI
Make Grand Central Dispatch easy and fun to use (queue, task, group, timer and semaphore). -
AsyncTimer
AsyncTimer is a precision asynchronous timer. You can also use it as a countdown timer
Appwrite - The Open Source Firebase alternative introduces iOS support
Appwrite is an open source backend server that helps you build native iOS applications much faster with realtime APIs for authentication, databases, files storage, cloud functions and much more!
Promo
appwrite.io
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Atomic or a related project?
Popular Comparisons
README
Atomic
Atomic is a fast, safe class for making values thread-safe in Swift. It is backed by pthread_mutex_lock
which is the fastest, most-efficient locking mechanism available.
Installation
- Using CocoaPods by adding
pod Atomic
to your Podfile - Using Carthage by adding
github "Adlai-Holler/Atomic"
to your Cartfile.
How to Use
/// This class is completely thread-safe (yay!).
final class MyCache<Value> {
private let entries: Atomic<[String: Value]> = Atomic([:])
func valueForKey(key: String) -> Value? {
return entries.withValue { $0[key] }
}
func setValue(value: Value, forKey: Key) {
entries.modify { (var dict) in
dict[key] = value
return dict
}
}
func clear() {
entries.value = [:]
}
func copy() -> [String: Value] {
return entries.value
}
}
Another Example
/// Thread-safe manager for the `networkActivityIndicator` on iOS.
final class NetworkActivityIndicatorManager {
static let shared = NetworkActivityIndicatorManager()
private let count = Atomic(0)
func incrementActivityCount() {
let oldValue = count.modify { $0 + 1 }
if oldValue == 0 {
updateUI(true)
}
}
func decrementActivityCount() {
let oldValue = count.modify { $0 - 1 }
if oldValue == 1 {
updateUI(false)
}
}
private func updateUI(on: Bool) {
dispatch_async(dispatch_get_main_queue()) {
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
}
}
}
Features
- Safe. No need to remember to unlock.
- Fast.
pthread_mutex_lock
is faster thanNSLock
and more efficient thanOSSpinLock
. - Modern. You can safely
throw
errors inside its methods, uses@noescape
and generics to make your code as clean as possible. - Tested. This thing is tested like crazy, including accessing it concurrently from 100,000 operations!
Attribution
The original version of Atomic.swift
was written by the ReactiveCocoa contributors.