Swiftpack.co - mediamonks/MMMCataphote as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by mediamonks.
mediamonks/MMMCataphote 1.0.3
Limited reflection for Swift Decodable types.
⭐️ 1
🕓 2 years ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/mediamonks/MMMCataphote.git", from: "1.0.3")

MMMCataphote

Build Test

Limited reflection for Decodable types.

(This is a part of MMMTemple suite of iOS libraries we use at MediaMonks.)

The main objective for this is to be able to automatically generate lists of object fields and child entities to be included into responses when working with JSONAPI-style responses.

Limitations:

  1. there is very limited support for enum fields (only the ones that can decode from a string "dummy");
  2. any dictionary is assumed to have String keys, could be resolved by parsing type names;
  3. it might not work well with Decodables that use custom initializers.

Installation

Podfile:

source 'https://github.com/mediamonks/MMMSpecs.git'
source 'https://cdn.cocoapods.org/'
...
pod 'MMMCataphote'

SPM:

.package(url: "https://github.com/mediamonks/MMMCataphote", .upToNextMajor(from: "1.0.3"))

Usage

A quick example here:

import MMMCataphote

struct Person: Decodable {
	let id: Int
	let name: String
	let height: Height
}

struct Height: Decodable {
	let height: Double
}

print(MMMCataphote.reflect(Person.self))

Prints the following:

Object(Person) where:

Height:
- height: Double

Person:
- height: Object(Height)
- id: Int
- name: String

I.e. the value returned by MMMCataphote.reflect can be browsed to automatically build the lists of fields or entities to include into JSONAPI-like responses, for example.

Ready for liftoff? 🚀

We're always looking for talent. Join one of the fastest-growing rocket ships in the business. Head over to our careers page for more info!

GitHub

link
Stars: 1
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

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