{"id":22338960,"url":"https://github.com/interfacelab/swiftencoderkit","last_synced_at":"2025-03-26T08:44:09.413Z","repository":{"id":153230491,"uuid":"49116637","full_name":"Interfacelab/SwiftEncoderKit","owner":"Interfacelab","description":null,"archived":false,"fork":false,"pushed_at":"2016-01-07T12:14:58.000Z","size":996,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-31T10:16:02.486Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Interfacelab.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":"2016-01-06T06:13:18.000Z","updated_at":"2021-05-18T10:20:41.000Z","dependencies_parsed_at":"2023-04-17T22:16:21.194Z","dependency_job_id":null,"html_url":"https://github.com/Interfacelab/SwiftEncoderKit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Interfacelab%2FSwiftEncoderKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Interfacelab%2FSwiftEncoderKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Interfacelab%2FSwiftEncoderKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Interfacelab%2FSwiftEncoderKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Interfacelab","download_url":"https://codeload.github.com/Interfacelab/SwiftEncoderKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245622940,"owners_count":20645678,"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":[],"created_at":"2024-12-04T07:06:13.770Z","updated_at":"2025-03-26T08:44:09.383Z","avatar_url":"https://github.com/Interfacelab.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"SwiftEncoderKit\n===============\n[![Build Status](https://travis-ci.org/Interfacelab/SwiftEncoderKit.svg?branch=master)](https://travis-ci.org/Hearst-DD/ObjectMapper)\n\nSerializing and deserializing object graphs in Swift boils down to four options: using JSON via ObjectMapper or similar, using CoreData, using NSKeyedArchiver via NSCoding and a whole lot of boilerplate code, or writing your own serialization/deserialization framework.\n\nSwiftEncoderKit \"wraps\" NSKeyedArchiver and adds the ability to encode Swift structs and enums - as well as encoding all of the basic types, NSCoding compliant classes and commonly used C structs (CGPoint, CGRect, etc.).\n\n\n# Basic Usage\n\nTo encode a class or struct, you simply need to implement the `Encodable` protocol, which is eerily similar to the `NSCoding` protocol:\n\n\n```swift\nclass EncodableModel: Encodable {\n    var rect: CGRect = CGRect.zero\n    var rotation: Float = 0.0\n    var previewImage: UIImage!\n    var animationTimes: [CMTime] = []\n\n    init() {\n        previewImage = UIImage(named: \"test.png\")\n    }\n\n    required init?(_ decoder: Decoder) {\n        rect \u003c-- decoder[\"rect\"]\n        rotation \u003c-- decoder[\"rotation\"]\n        previewImage \u003c-- decoder[\"previewImage\"]\n        animationTimes \u003c-- decoder[\"animationTimes\"]\n    }\n\n    func encode(encoder: Encoder) {\n        rect --\u003e encoder[\"rect\"]\n        rotation --\u003e encoder[\"rotation\"]\n        previewImage --\u003e encoder[\"previewImage\"]\n        animationTimes --\u003e encoder[\"animationTimes\"]\n    }\n}\n```\n\nTo encode the model to file:\n\n```swift\nlet model = EncodableModel()\nEncoder(model).writeToFile(\"somefile.plist\")\n```\n\nTo decode the model:\n\n```swift\nlet model: EncodableModel? = Decoder(\"somefile.plist\").decodedObject()\n```\n\n\n# Supported Types\n\nSwiftEncoderKit supports encoding the following types out of the box:\n\n- Int (Int, Int8, Int16, Int32, Int64)\n- UInt (UInt, UInt8 UInt16, UInt32, UInt64)\n- String\n- Bool\n- Float\n- Double\n- Any object conforming to `NSCoding` protocol (UIColor, UIImage, NSData, etc)\n- Any object conforming to `Encodable` protocol\n- Typed enums\n- CGRect, CGPoint, CGSize, CGVector, CGAffineTransform, CATransform3D\n- CMTime, CMTimeRange, CMTimeMapping\n- Arrays of the above\n- Dictionaries of the above\n- Optionals and implicitly unwrapped optionals of the above (including Arrays and Dictionaries)\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finterfacelab%2Fswiftencoderkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finterfacelab%2Fswiftencoderkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finterfacelab%2Fswiftencoderkit/lists"}