{"id":15038058,"url":"https://github.com/otbivnoe/codablealamofire","last_synced_at":"2025-10-04T03:31:49.268Z","repository":{"id":47506010,"uuid":"93938955","full_name":"Otbivnoe/CodableAlamofire","owner":"Otbivnoe","description":"An extension for Alamofire that converts JSON data into Decodable objects.","archived":true,"fork":false,"pushed_at":"2021-09-20T18:36:14.000Z","size":113,"stargazers_count":740,"open_issues_count":2,"forks_count":54,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-10-03T05:20:19.458Z","etag":null,"topics":["alamofire","ios","json","mapping","parsing-library","swfit","swift4"],"latest_commit_sha":null,"homepage":"","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/Otbivnoe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-10T12:54:10.000Z","updated_at":"2024-09-26T03:25:47.000Z","dependencies_parsed_at":"2022-08-21T03:20:45.088Z","dependency_job_id":null,"html_url":"https://github.com/Otbivnoe/CodableAlamofire","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/Otbivnoe/CodableAlamofire","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Otbivnoe%2FCodableAlamofire","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Otbivnoe%2FCodableAlamofire/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Otbivnoe%2FCodableAlamofire/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Otbivnoe%2FCodableAlamofire/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Otbivnoe","download_url":"https://codeload.github.com/Otbivnoe/CodableAlamofire/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Otbivnoe%2FCodableAlamofire/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278259829,"owners_count":25957547,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["alamofire","ios","json","mapping","parsing-library","swfit","swift4"],"created_at":"2024-09-24T20:36:56.154Z","updated_at":"2025-10-04T03:31:49.022Z","avatar_url":"https://github.com/Otbivnoe.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"http://i.imgur.com/x2E68WN.png\" alt=\"CodableAlamofire\"/\u003e\n\u003c/p\u003e\n\n[![Build Status](https://travis-ci.org/Otbivnoe/CodableAlamofire.svg?branch=master)](https://travis-ci.org/Otbivnoe/CodableAlamofire)\n![Swift 5.x](https://img.shields.io/badge/Swift-5.x-orange)\n[![SPM compatible](https://img.shields.io/badge/SPM-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)\n[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Version](https://img.shields.io/cocoapods/v/CodableAlamofire.svg?style=flat)](http://cocoadocs.org/docsets/CodableAlamofire)\n![platforms](https://img.shields.io/badge/platforms-iOS%20%7C%20macOS%20%7C%20tvOS%20%7C%20watchOS%20%7C%20Linux-333333.svg)\n\n**Swift 4 introduces a new `Codable` protocol that lets you serialize and deserialize custom data types without writing any special code and without having to worry about losing your value types. 🎉**\n\n**Awesome, isn't it? And this library helps you write less code! It's an extension for `Alamofire` that converts `JSON` data into `Decodable` object.**\n\n### Useful Resources:\n- [Encoding and Decoding Custom Types](https://developer.apple.com/documentation/foundation/archives_and_serialization/encoding_and_decoding_custom_types) - Article by Apple\n- [Using JSON with Custom Types](https://developer.apple.com/documentation/foundation/archives_and_serialization/using_json_with_custom_types) - Swift Playground\n- Also there is a special session from `WWDC2017` that covers this new feature - [What's New in Foundation](https://developer.apple.com/videos/play/wwdc2017/212/)\n\n# Usage\n\nLet's decode a simple json file:\n```\n{\n    \"result\": {\n        \"libraries\": [\n            {\n                \"name\": \"Alamofire\",\n                \"stars\": 23857,\n                \"url\": \"https://github.com/Alamofire/Alamofire\",\n                \"random_date_commit\": 1489276800\n            },\n            {\n                \"name\": \"RxSwift\",\n                \"stars\": 9600,\n                \"url\": \"https://github.com/ReactiveX/RxSwift\",\n                \"random_date_commit\": 1494547200\n            }\t\n        ]\n    }\n}\n```\n\nwith the following Swift model: \n\n```swift\nprivate struct Repo: Decodable {\n    let name: String\n    let stars: Int\n    let url: URL\n    let randomDateCommit: Date\n    \n    private enum CodingKeys: String, CodingKey {\n        case name\n        case stars\n        case url\n        case randomDateCommit = \"random_date_commit\"\n    }\n}\n```\n\nThere is a similar method to `responseData`, `responseJSON` - **`responseDecodableObject`**:\n\n```swift \nfunc responseDecodableObject\u003cT: Decodable\u003e(queue: DispatchQueue? = nil, keyPath: String? = nil, decoder: JSONDecoder = JSONDecoder(), completionHandler: @escaping (AFDataResponse\u003cT\u003e) -\u003e Void)\n```\n\n- `queue` - The queue on which the completion handler is dispatched.\n- `keyPath` - The keyPath where object decoding should be performed.\n- `decoder` - The decoder that performs the decoding of JSON into semantic `Decodable` type.\n\n```swift\nlet url = URL(string: \"https://raw.githubusercontent.com/otbivnoe/CodableAlamofire/master/keypathArray.json\")!\nlet decoder = JSONDecoder()\ndecoder.dateDecodingStrategy = .secondsSince1970 // It is necessary for correct decoding. Timestamp -\u003e Date.\n\nAF.request(url).responseDecodableObject(keyPath: \"result.libraries\", decoder: decoder) { (response: AFDataResponse\u003c[Repo]\u003e) in\n    let repo = response.value\n    print(repo)\n}\n```\n\n### Note: \n - For array: `DataResponse\u003c[Repo]\u003e`\n - For single object: `DataResponse\u003cRepo\u003e`\n\n# Requirements\n - Swift 4+\n - Xcode 9+\n\n# Installation 🔥\n\n## CocoaPods\n\n[CocoaPods](http://cocoapods.org) is a dependency manager for Swift and Objective-C Cocoa projects. It has over eighteen thousand libraries and can help you scale your projects elegantly. You can install it with the following command:\n\n```bash\n$ sudo gem install cocoapods\n```\n\nTo integrate CodableAlamofire, simply add the following line to your `Podfile`:\n\n```ruby\ntarget 'Test' do\n  use_frameworks!\n\n  pod 'CodableAlamofire'\n  \nend\n```\n\n## Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.\n\nYou can install Carthage with [Homebrew](http://brew.sh/) using the following command:\n\n```bash\n$ brew update\n$ brew install carthage\n```\nTo integrate CodableAlamofire into your Xcode project using Carthage, specify it in your `Cartfile`:\n```odgl\ngithub \"Otbivnoe/CodableAlamofire\"\n```\n\nRun `carthage update` to build the framework and drag the built `CodableAlamofire.framework` into your Xcode project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fotbivnoe%2Fcodablealamofire","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fotbivnoe%2Fcodablealamofire","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fotbivnoe%2Fcodablealamofire/lists"}