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:
String
keys, could be resolved by parsing type names;Decodable
s that use custom initializers.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"))
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.
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!
link |
Stars: 1 |
Last commit: 1 year ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics