Swiftpack.co - AndrewSB/Expirable as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by AndrewSB.
AndrewSB/Expirable v1.0.0
A Swift µ-Library for modeling and reacting to values that expire
⭐️ 10
🕓 3 years ago
iOS
.package(url: "https://github.com/AndrewSB/Expirable.git", from: "v1.0.0")

Expirable

A Swift µ-Library for modeling and reacting to values that expire

Rationale

I wrote this while dealing with a number of expiring values (nonces from a hardware device, OAuth tokens, command tokens to send to hardware) during my time at Proxy.

It's a one-file dependency that exposes an Expirable protocol. Once implemented by a object that models some data that becomes stale at some point in the future, you get a number of convienient ways to deal with and react to said data expiring

Installation

The package is available through

  • Swift package manager
  • Carthage
  • Manual copying of the one file

Sample usage

You can check out the Example.playground to see an example of the library in use. Make sure you carthage bootstrap and build the Expirable framework, the playground can't run without them.

API

Expirable

The protocol exposed in this micro library, it expects two pieces of data

expiresAt: Date the date at which the data expires
expirationMarginInterval: TimeInterval an interval preceeding the expiry used to send a message of impending expiry
isValid: Bool

syncronous access to whether the object has expired

isExpiredOrExpiringSoon: Bool

syncronous access to whether the object has expired or is about to expire, based on subtracting the expirationMarginInterval from the expiresAt date

expiresSoon: Observable<Void>

an observable that will fire as soon as the current date is greater than expiresAt - expirationMarginInterval.

GitHub

link
Stars: 10
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

RxSwift 3
7 years ago

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