Nibbles of useful swift code that I regularaly use across various proejcts.
To add swift-nibbles
to your project, first add it as a dependency.
.package(url: "https://github.com/connor-ricks/swift-nibbles/", branch: "main")
Nibbles are all broken down into their own targets, so you can choose which nibbles are relevant to your project.
.product(name: "Exchange", package: "swift-nibbles")
// or
.product(name: "Stash", package: "swift-nibbles")
An HTTP client that creates and manages requests over the network.
The client provides support for sharing common functionality across all requests, but each request can also layer on additional functionality if needed.
Using the concept of plugins, you can customize your client's functionalities to your needs.
- Adaptors: Mutate a
URLRequest
before it is dispatched over the network. Useful for adding headers or query parameters to outbound requests. - Validators Validate the
HTTPURLResponse
andData
of aURLRequest
before decoding. Useful for checking status codes and other common validation stratagies. - Retriers Retry failed requests on your terms.
Generally an HTTPClient
is used to manage the interaction with a single API service. Most APIs
have their own nuance and complexities, and encapsulating all of that in one place can help structure your code in a
more scalable and testable way.
A websocket created from a URL that can listen to messages send through the connection using AsyncStream
.
Sending messages and cancelling the connection is as easy as calling a few methods.
A collection of useful extensions that I freqeuntly implement across multiple projects.
A collection of useful Combine nibbles.
- A variety of helpful sinks that allow for easier less verbose interactions with Combine publishers.
- A variety of helpful sinks that automatically cleanup after themselves by using a
DisposableBag
. BuffableAsyncPublisher
andBuffableAsyncThrowingPublisher
which both expose avalues(bufferingStrategy:)
onPublisher
- This is a more configurable and powerful version of
values
in Combine that allows converting Combine to an async/await syntax.
- This is a more configurable and powerful version of
A protocol for marking objects as identified and allowing interaction with their identifiers in a type-safe way.
A simple container that encapsulates an object allowing others to subscribe to and monitor changes to the state.
Frequently use in PointFree's TCA architecture to subscribe long-running effects to shared state changes.
A simple cache that can be used to store objects.
Use a Stash
to store objects of a given type in memory using an associated key.
You can then fetch attempt to retrieve from the Stash
at a later time using the key.
A simple property wrapper that allows your views to optionally take a binding and default to internal state. Useful when creating reusable components.