{"id":20590855,"url":"https://github.com/alickbass/codablefirebase","last_synced_at":"2025-05-16T12:12:29.760Z","repository":{"id":26254511,"uuid":"107771334","full_name":"alickbass/CodableFirebase","owner":"alickbass","description":"Use Codable with Firebase","archived":false,"fork":false,"pushed_at":"2022-10-06T00:44:10.000Z","size":123,"stargazers_count":694,"open_issues_count":43,"forks_count":91,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-05-15T03:51:34.199Z","etag":null,"topics":["codable","firebase-database","firebase-firestore","swift"],"latest_commit_sha":null,"homepage":null,"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/alickbass.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-21T10:30:55.000Z","updated_at":"2025-04-30T02:25:59.000Z","dependencies_parsed_at":"2022-08-07T12:00:10.296Z","dependency_job_id":null,"html_url":"https://github.com/alickbass/CodableFirebase","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alickbass%2FCodableFirebase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alickbass%2FCodableFirebase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alickbass%2FCodableFirebase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alickbass%2FCodableFirebase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alickbass","download_url":"https://codeload.github.com/alickbass/CodableFirebase/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254527099,"owners_count":22085919,"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","firebase-database","firebase-firestore","swift"],"created_at":"2024-11-16T07:38:27.424Z","updated_at":"2025-05-16T12:12:24.744Z","avatar_url":"https://github.com/alickbass.png","language":"Swift","readme":"# CodableFirebase\nUse [Codable](https://developer.apple.com/documentation/swift/codable) with [Firebase](https://firebase.google.com)\n\n[![CocoaPods](https://img.shields.io/cocoapods/p/CodableFirebase.svg)](https://github.com/alickbass/CodableFirebase)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) \n[![Build Status](https://travis-ci.org/alickbass/CodableFirebase.svg?branch=master)](https://travis-ci.org/alickbass/CodableFirebase)\n\n## Overview\n\nThis library helps you to use your custom types that conform to `Codable` protocol with Firebase. Here's an example of a custom model:\n\n```swift\nstruct Model: Codable {\n    enum MyEnum: Int, Codable {\n        case one, two, three\n    }\n    \n    let stringExample: String\n    let booleanExample: Bool\n    let numberExample: Double\n    let dateExample: Date\n    let arrayExample: [String]\n    let optionalExample: Int?\n    let objectExample: [String: String]\n    let myEnumExample: MyEnum\n}\n```\n\n### Firebase Realtime Database usage\n\nThis is how you would use the library with [Firebase Realtime Database](https://firebase.google.com/products/realtime-database/):\n\n```swift\nimport Firebase\nimport CodableFirebase\n\nlet model: Model // here you will create an instance of Model\nlet data = try! FirebaseEncoder().encode(model)\n\nDatabase.database().reference().child(\"model\").setValue(data)\n```\n\nAnd here is how you would read the same value from [Firebase Realtime Database](https://firebase.google.com/products/realtime-database/):\n\n```swift\nDatabase.database().reference().child(\"model\").observeSingleEvent(of: .value, with: { snapshot in\n    guard let value = snapshot.value else { return }\n    do {\n        let model = try FirebaseDecoder().decode(Model.self, from: value)\n        print(model)\n    } catch let error {\n        print(error)\n    }\n})\n```\n\n### Firebase Cloud Firestore usage\n\nThis is how you would encode a model with [Firebase Cloud Firestore](https://firebase.google.com/products/firestore/):\n\n```swift\nimport Firebase\nimport CodableFirebase\n\nlet model: Model // here you will create an instance of Model\nlet docData = try! FirestoreEncoder().encode(model)\nFirestore.firestore().collection(\"data\").document(\"one\").setData(docData) { error in\n    if let error = error {\n        print(\"Error writing document: \\(error)\")\n    } else {\n        print(\"Document successfully written!\")\n    }\n}\n```\n\nAnd this is how you would decode the same model with [Firebase Cloud Firestore](https://firebase.google.com/products/firestore/):\n\n```swift\nFirestore.firestore().collection(\"data\").document(\"one\").getDocument { document, error in\n    if let document = document {\n        let model = try! FirestoreDecoder().decode(Model.self, from: document.data())\n        print(\"Model: \\(model)\")\n    } else {\n        print(\"Document does not exist\")\n    }\n}\n```\n\n#### How to use `GeoPoint`, `DocumentRefence`, `FieldValue`, `Timestamp` in Cloud Firestore\n\nIn order to use these types with Cloud Firestore, you need to add the following code somewhere in your app:\n\n```swift\nextension DocumentReference: DocumentReferenceType {}\nextension GeoPoint: GeoPointType {}\nextension FieldValue: FieldValueType {}\nextension Timestamp: TimestampType {}\n```\n\nand now they become `Codable` and can be used properly with `FirestoreEncoder` and `FirestoreDecoder`.\n\n***PLEASE NOTE*** that as `FieldValue` is only used to [`setData()` and `updateData()`](https://firebase.google.com/docs/reference/swift/firebasefirestore/api/reference/Classes/FieldValue), it only adopts the `Encodable` protocol. \n\n## Integration\n\n### CocoaPods (iOS 9+)\n\nYou can use CocoaPods to install CodableFirebase by adding it to your Podfile:\n\n```swift\nplatform :ios, '9.0'\nuse_frameworks!\n\ntarget 'MyApp' do\n  pod 'CodableFirebase'\nend\n```\n\nNote that this requires CocoaPods version 36, and your iOS deployment target to be at least 9.0:\n\n### Carthage (iOS 9+)\n\nYou can use Carthage to install CodableFirebase by adding it to your Cartfile:\n\n```swift\ngithub \"alickbass/CodableFirebase\"\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falickbass%2Fcodablefirebase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falickbass%2Fcodablefirebase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falickbass%2Fcodablefirebase/lists"}