Swiftpack.co - Enchan1207/Serializable as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Enchan1207.
Enchan1207/Serializable v1.0.0
Extended Codable Protocol
⭐️ 0
🕓 2 years ago
.package(url: "https://github.com/Enchan1207/Serializable.git", from: "v1.0.0")

Serializable

Overview

Extended Codable Protocol

Usage

First, make the structure compliant with the protocol Serializable.

struct Article: Serializable {
    let id: String
    let title: String
    let tag: [String]
    let content: String
}

Serialize (object to JSON string):

let article = Article(id: "001", title: "Hello!", tag: ["Introduction"], content: "# Hi there! I'm Enchan.")

let serialized = article.serialize()!
print(serialized)

Deserialize (JSON string to object):

let deserialized = "{"id":"001","title":"Hello!","content":"# Hi there! I'm Enchan.","tag":["Introduction"]}"

let article = Article.deserialize(object: deserialized)!
print(article)

License

This repository is published under MIT License.
In details, see LICENSE.

GitHub

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

Release Notes

2 years ago

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