{"id":13872286,"url":"https://github.com/Flight-School/Codable-DIY-Kit","last_synced_at":"2025-07-16T02:30:30.165Z","repository":{"id":49812981,"uuid":"132485202","full_name":"Flight-School/Codable-DIY-Kit","owner":"Flight-School","description":"A template for creating your own Swift Codable encoders and decoders","archived":false,"fork":false,"pushed_at":"2020-03-30T19:08:46.000Z","size":13,"stargazers_count":228,"open_issues_count":2,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-06T23:51:54.404Z","etag":null,"topics":["codable","decoder","encoder","swift"],"latest_commit_sha":null,"homepage":"https://flight.school/books/codable","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Flight-School.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["mattt"],"custom":"https://flight.school/books/codable"}},"created_at":"2018-05-07T16:06:18.000Z","updated_at":"2024-08-02T02:51:46.000Z","dependencies_parsed_at":"2022-09-13T11:11:43.009Z","dependency_job_id":null,"html_url":"https://github.com/Flight-School/Codable-DIY-Kit","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flight-School%2FCodable-DIY-Kit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flight-School%2FCodable-DIY-Kit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flight-School%2FCodable-DIY-Kit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flight-School%2FCodable-DIY-Kit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Flight-School","download_url":"https://codeload.github.com/Flight-School/Codable-DIY-Kit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226095632,"owners_count":17572966,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codable","decoder","encoder","swift"],"created_at":"2024-08-05T23:00:38.725Z","updated_at":"2024-11-23T20:30:49.911Z","avatar_url":"https://github.com/Flight-School.png","language":"Swift","funding_links":["https://github.com/sponsors/mattt","https://flight.school/books/codable"],"categories":["Swift"],"sub_categories":[],"readme":"# DIY Codable Encoder / Decoder Kit\n\nIn Swift 4,\na type that conforms to the `Codable` protocol\ncan be encoded to or decoded from representations\nfor any format that implements a corresponding `Encoder` or `Decoder` type.\n\nAt the time of its release,\nthe only reference implementations for these types\nwere the Foundation framework's `JSONEncoder` / `JSONDecoder`\nand `PropertyListEncoder` and `PropertyListDecoder`.\nThe [implementation details](https://github.com/apple/swift/blob/master/stdlib/public/SDK/Foundation/JSONEncoder.swift)\nof these types, however,\nare obfuscated by translation logic from\n`JSONSerialization` and `PropertyListSerialization`.\n\nThis repository provides a template\nthat makes it easier for developers\nto create encoders and decoders for custom formats.\nThe template includes stubbed placeholders for the required types and methods\nas well as simple tests for encoding and decoding `Codable` types.\n\nThis general structure was used to implement a `Codable`-compatible\n[encoder and decoder for the MessagePack format](https://github.com/flight-school/messagepack).\n\nFor more information about the design and implementation\nof custom encoder and decoder types,\nsee Chapter 7 of\n[Flight School Guide to Swift Codable](https://flight.school/books/codable).\n\n## Usage\n\n* Clone this repository\n* Find all instances of the \"\u003c#Format#\u003e\" placeholder\n  and replace with the name of your own format\n* Replace the leading underscores in the\n  `___Decoder.swift` and `___Encoder.swift` files,\n  as well as the source files in the Tests directory\n* Run the command `swift package generate-xcodeproj`\n  in the root project directory\n* Fill in the missing implementation accordingly\n\n### Encoder Structure\n\n```swift\npublic class \u003c#Format#\u003eEncoder {\n    public func encode\u003cT\u003e(_ value: T) throws -\u003e Data\n                        where T : Encodable\n}\n\nfinal class _\u003c#Format#\u003eEncoder: Encoder {\n    final class SingleValueContainer: SingleValueEncodingContainer\n    final class UnkeyedContainer: UnkeyedEncodingContainer\n    final class KeyedContainer\u003cKey\u003e: KeyedEncodingContainerProtocol\n            where Key: CodingKey\n}\n\nprotocol \u003c#Format#\u003eEncodingContainer: class {}\n```\n\n### Decoder Structure\n\n```swift\npublic class \u003c#Format#\u003eDecoder {\n    public func decode\u003cT\u003e(_ type: T.Type,\n                          from data: Data) throws -\u003e T\n                        where T : Decodable\n}\n\nfinal class _\u003c#Format#\u003eDecoder: Decoder {\n    final class SingleValueContainer: SingleValueDecodingContainer\n    final class UnkeyedContainer: UnkeyedDecodingContainer\n    final class KeyedContainer\u003cKey\u003e: KeyedContainer\n            where Key: CodingKey\n}\n\nprotocol \u003c#Format#\u003eDecodingContainer: class {}\n```\n\n## License\n\nMIT\n\n## Contact\n\nMattt ([@mattt](https://twitter.com/mattt))\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFlight-School%2FCodable-DIY-Kit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFlight-School%2FCodable-DIY-Kit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFlight-School%2FCodable-DIY-Kit/lists"}