Skip to content
Swift Concurrent Collections
Swift Objective-C
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
SwiftConcurrentCollections.xcodeproj
SwiftConcurrentCollections Use pthread_rwlock_t instead of GCD Feb 9, 2020
SwiftConcurrentCollectionsTests Use pthread_rwlock_t instead of GCD Feb 9, 2020
.gitignore Initial commit Feb 3, 2020
LICENSE Initial commit Feb 3, 2020
README.md

README.md

SwiftConcurrentCollections

Intro

Swift Concurrent Collections is a library providing concurrent (thread-safe) implementations of some of default Swift collections. Similar to ones found in java.util.concurrent for Java.

Installation

Carthage

In your Xcode project folder do:

  • echo "github \"peterprokop/SwiftConcurrentCollections\" == 1.2.0" >> Cartfile (or use nano)
  • Run carthage update
  • Add SwiftConcurrentCollections to your carthage copy-frameworks phase
  • Add import SwiftConcurrentCollections in files where you plan to use it

Usage

Do import SwiftConcurrentCollections

Then you can use concurrent collections from different threads without fear of crashes or data corruption

let concurrentArray = ConcurrentArray<Int>()
concurrentArray.append(value)
print(concurrentArray[0])
let concurrentDictionary = ConcurrentDictionary<String, Int>()
concurrentDictionary[key] = value
print(concurrentDictionary[key])

Safe array subscript: for atomicity of checking if specified index is in the array and getting element with that index use

if let element = concurrentArray[safe: index] {
    // ...
}

instead of

if index < concurrentArray.count {
    let element = concurrentArray[index]
    // ...
}
You can’t perform that action at this time.