Swiftpack.co -  aplr/Pillarbox as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
aplr/Pillarbox
An object-based Queue for iOS, tvOS and macOS, written in Swift.
.package(url: "https://github.com/aplr/Pillarbox.git", from: "1.0.1")

Pillarbox

Build Documentation

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.

About Pillarbox

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.

Installation

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")
    )
]

Usage

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

Going LIFO

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

Documentation is available here and provides a comprehensive documentation of the library's public interface. Expect usage examples and guides to be added shortly.

License

Pillarbox is licensed under the MIT License.

GitHub

link
Stars: 3
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Pillarbox 1.0.1
1 week ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API