An open API service indexing awesome lists of open source software.

https://github.com/sinoru/swift-snowflake

A Swift library for Snowflake ID.
https://github.com/sinoru/swift-snowflake

ios linux macos snowflake snowflake-twitter swift swiftpm tvos watchos

Last synced: about 1 month ago
JSON representation

A Swift library for Snowflake ID.

Awesome Lists containing this project

README

          

# swift-snowflake

| **main** | **develop** |
|:---:|:---:|
| [![Test](https://github.com/sinoru/swift-snowflake/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/sinoru/swift-snowflake/actions/workflows/test.yml) | [![Test](https://github.com/sinoru/swift-snowflake/actions/workflows/test.yml/badge.svg?branch=develop)](https://github.com/sinoru/swift-snowflake/actions/workflows/test.yml) |

A Swift library for [Snowflake ID](https://en.wikipedia.org/wiki/Snowflake_ID).

## Package Products

* [`Snowflake`][snowflake-docs], main library that contains `Snowflake`. (without importing Foundation)
* [`SnowflakeFoundationCompat`][snowflake-foundation-compat-docs], library that contains make `Snowflake` interoperate better with Foundation.
* `JSONDecoder`, `JSONEncoder` extensions for easily using on JSON parse.

[snowflake-docs]: https://swiftpackageindex.com/sinoru/swift-snowflake/documentation/snowflake
[snowflake-foundation-compat-docs]: https://swiftpackageindex.com/sinoru/swift-snowflake/documentation/snowflakefoundationcompat

## Supported Platforms

swift-snowflake aims to support all of the platforms where Swift 5.3 or later is supported.

## Example

```swift
import Snowflake

let someSnowflakeID: Snowflake = 1822504365596868608
```

```swift
import SnowflakeFoundationCompat

let examples: [Snowflake] = [175928847299117063, 1541815603606036480]

let jsonEncoder = JSONEncoder()
jsonEncoder.snowflakeEncodingStrategy = .number

let data = try jsonEncoder.encode(examples)

```

## Using **swift-snowflake** in your project

To use this package in a SwiftPM project, you need to set it up as a package dependency:

```swift
// swift-tools-version:5.3
import PackageDescription

let package = Package(
name: "MyPackage",
dependencies: [
.package(
url: "https://github.com/sinoru/swift-snowflake.git",
.upToNextMajor(from: "1.0.0") // or `.upToNextMinor
)
],
targets: [
.target(
name: "MyTarget",
dependencies: [
.product(name: "Snowflake", package: "swift-snowflake")
]
)
]
)
```