{"id":32149464,"url":"https://github.com/the-yuyut/supercodable","last_synced_at":"2026-02-19T08:01:49.394Z","repository":{"id":52968689,"uuid":"356553845","full_name":"the-yuyut/SuperCodable","owner":"the-yuyut","description":"Codable, but with Super power made custom Codable behavior easy.","archived":false,"fork":false,"pushed_at":"2021-09-14T11:07:19.000Z","size":48,"stargazers_count":24,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-22T18:40:34.181Z","etag":null,"topics":["codable","easy-to-use","propertywrapper","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/the-yuyut.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-10T10:58:07.000Z","updated_at":"2025-01-13T01:00:23.000Z","dependencies_parsed_at":"2022-09-03T02:42:32.441Z","dependency_job_id":null,"html_url":"https://github.com/the-yuyut/SuperCodable","commit_stats":null,"previous_names":["the-yuyut/supercodable","ytyubox/supercodable"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/the-yuyut/SuperCodable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-yuyut%2FSuperCodable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-yuyut%2FSuperCodable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-yuyut%2FSuperCodable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-yuyut%2FSuperCodable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/the-yuyut","download_url":"https://codeload.github.com/the-yuyut/SuperCodable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-yuyut%2FSuperCodable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29608152,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T06:47:36.664Z","status":"ssl_error","status_checked_at":"2026-02-19T06:45:47.551Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","easy-to-use","propertywrapper","swift"],"created_at":"2025-10-21T09:58:09.065Z","updated_at":"2026-02-19T08:01:49.389Z","avatar_url":"https://github.com/the-yuyut.png","language":"Swift","readme":"# SuperCodable\n\n\n##  From Foundation\n\n```swift\nstruct AStudent: Codable {\n    init(from decoder: Decoder) throws {\n        let container = try decoder.container(keyedBy: CodingKeys.self)\n        self.aID = try container.decode(String.self, forKey: .aID)\n        self.aName = try container.decode(String.self, forKey: .aName)\n        let gradeDecoded = try container.decode(Double.self, forKey: .aGrade)\n        self.AGrede = Int(gradeDecoded)\n    }\n\n    enum CodingKeys: String, CodingKey {\n        case aName = \"name\"\n        case aGrade = \"grade\"\n        case aID = \"id\"\n    }\n\n    var aID: String\n    var aName: String\n    var AGrede: Int\n\n    func encode(to encoder: Encoder) throws {\n        var container = encoder.container(keyedBy: CodingKeys.self)\n        try container.encode(aID, forKey: .aID)\n        try container.encode(Double(AGrede), forKey: .aGrade)\n        try container.encode(aName, forKey: .aName)\n    }\n}\n```\n\n\n## To SuperCodable\n\n```swift\nstruct Student: SuperCodable {\n    @Keyed\n    var id: String\n    \n    @Keyed(\"name\") \n    var aName: String\n    \n    @KeyedTransform(\"grade\", doubleTransform)\n    var AGrade: Int\n}\n\nlet doubleTransform = SCTransformOf\u003cInt, Double\u003e {\n    (double) -\u003e Int in\n    Int(double)\n} toEncoder: { (int) -\u003e Double in\n    Double(int)\n}\n```\n\n## Even random backend type\n\n```swift\nstruct AnyValueJSON: SuperCodable {\n    @KeyedTransform(IDTransform)\n    var id:Int\n}\n\n let data =\n    #\"\"\"\n    [\n        {\n            \"id\": \"0\",\n        },\n        {\n            \"id\": 1,\n        },\n        {\n            \"id\": \"abc\",\n        },\n        {\n            \"id\": true,\n        },\n    ]\n    \"\"\"#.data(using: .utf8)!\nlet sut = try! JSONDecoder().decode([AnyValueJSON].self, from: data)\nXCTAssertEqual(sut.count, 4)\nXCTAssertEqual(sut.map(\\.id), [0, 1, 0, 1])\n```\n\nCan be found in [Tests/SuperCodableTests/AnyValueDecode.swift](Tests/SuperCodableTests/AnyValueDecode.swift)\n\n## Feature\n\n- Working with Nested `Foundation.Codable` property\n\n## Known side effect \n\n- SuperDecoable must construct from nothing `init()`\n- `@Keyed var id:Int` will do **O(n) calculation** on underlaying wrapper `_VARIABLE_NAME` into key `VARIABLE_NAME`. **Be ware of variable name takes too long**\n\n\n## Known Disability\n\n- Every property in a SuperCodable should a `DecodableKey` / `EncodableKey`, otherwise the property(which should be `Codable`) will **simply ignored** during the Codable process.\n\u003e Why:\n\u003e\u003e Basically Mirror can't mutating the object value during the  `init(from decoder:) throws`, since we create the object from `self.init()`\n\n\n## Other notes\n\n- Inspired by: https://medium.com/trueid-developers/combined-propertywrapper-with-codable-swift-368dc4aa2703\n\n- Try to merge `@KeyedTransform` into `@Keyed`, but it required `@Keyed var id: String` to be `@Keyed() var id: String`, with extra `()` 🧐\n\n- Swift should auto generate `STRUCT.init(....)` for you, **but** if you using `@Keyed var id: String` without default value, it will generate `init(id: Keyed\u003cString\u003e)`, by giving default value `@Keyed var id: String = \"\"` should solve this problem. \n\n## Know Issues\n\n- `@Keyed var id:String?` will cause fatalError on force unwrapping `Keyed.value?`, you can using `@OptionalKeyed` to make it works.\n- `OptionalKeyed` may / may not a good name, I am thinking of make the easy to change, maybe `KeyedOptional` is EASY change? 🤔\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthe-yuyut%2Fsupercodable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthe-yuyut%2Fsupercodable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthe-yuyut%2Fsupercodable/lists"}