Pillarbox is an easy-to-use, object-based queue with support for iOS, tvOS and macOS, written purely in Swift. Push and pop operations are both in O(1). All writes are synchronous - this means data will be written to the disk before an operation returns. Furthermore, all operations are thread-safe and synchronized using a read-write lock. This allows for synchronized, concurrent access to read-operations while performing writes in serial.
Pillarbox was originally conceived as a simple object queue that allows to persist unsent messages locally in an efficient and simple way which outlasts app crashes and restarts. For its storage layer, Pillarbox makes use of Pinterest’s excellent PINCache, which is a key/value store designed for persisting temporary objects on the disk. Beyond that, the Deque data structure from Apple’s open source swift-collections library is used in the internal realization of the queue.
Pillarbox is available via the Swift Package Manager which is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system and automates the process of downloading, compiling, and linking dependencies.
Once you have your Swift package set up, adding Pillarbox as a dependency is as easy as adding it to the dependencies value of your Package.swift.
dependencies: [ .package( url: "https://github.com/aplr/Pillarbox.git", .upToNextMajor(from: "1.0.0") ) ]
As a bare minimum, you have to specify the name of the Pillarbox which determines the queue file name, as well as the directory where the queue file is stored.
import Pillarbox let url = URL(fileURLWithPath: "/path/to/your/app", isDirectory: true) let pillarbox = Pillarbox<String>(name: "messages", url: url) pillarbox.push("Hello") pillarbox.push("World") print(pillarbox.count) // 2 print(pillarbox.pop()) // "Hello" print(pillarbox.pop()) // "World" print(pillarbox.isEmpty) // true
Pillarbox uses a FIFO queue internally per default. If you want to change that behaviour to LIFO, pass a customized
PillarboxConfiguration object with the strategy adjusted like below.
let url = URL(fileURLWithPath: "/path/to/your/app", isDirectory: true) let configuration = PillarboxConfiguration(strategy: .lifo) let pillarbox = Pillarbox<String>( name: "messages", url: url, configuration: configuration ) // ...
Documentation is available here and provides a comprehensive documentation of the library’s public interface. Expect usage examples and guides to be added shortly.
Pillarbox is licensed under the MIT License.