{"id":25401940,"url":"https://github.com/markbattistella/swiftdatapreviewer","last_synced_at":"2026-04-14T15:33:29.166Z","repository":{"id":277282438,"uuid":"931926642","full_name":"markbattistella/SwiftDataPreviewer","owner":"markbattistella","description":"SwiftDataPreviewKit is a lightweight Swift package designed to simplify SwiftUI previews using SwiftData. It provides an in-memory model container for use in DEBUG builds, allowing you to preview your SwiftData-powered views with sample data.","archived":false,"fork":false,"pushed_at":"2025-02-17T04:56:53.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-26T10:42:36.861Z","etag":null,"topics":["ios","maccatalyst","macos","spm","swift","swift-package-manager","swiftdata","swiftui","tvos","visionos","watchos"],"latest_commit_sha":null,"homepage":"https://swiftpackageindex.com/markbattistella/SwiftDataPreviewKit/documentation","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/markbattistella.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["markbattistella"],"custom":["https://www.paypal.me/markbattistella/5AUD","https://www.paypal.me/markbattistella/10AUD","https://www.paypal.me/markbattistella/20AUD"]}},"created_at":"2025-02-13T04:39:46.000Z","updated_at":"2025-02-17T04:55:25.000Z","dependencies_parsed_at":"2025-04-12T09:09:35.746Z","dependency_job_id":null,"html_url":"https://github.com/markbattistella/SwiftDataPreviewer","commit_stats":null,"previous_names":["markbattistella/swiftdatapreviewer"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/markbattistella/SwiftDataPreviewer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markbattistella%2FSwiftDataPreviewer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markbattistella%2FSwiftDataPreviewer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markbattistella%2FSwiftDataPreviewer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markbattistella%2FSwiftDataPreviewer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markbattistella","download_url":"https://codeload.github.com/markbattistella/SwiftDataPreviewer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markbattistella%2FSwiftDataPreviewer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261373443,"owners_count":23148915,"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":["ios","maccatalyst","macos","spm","swift","swift-package-manager","swiftdata","swiftui","tvos","visionos","watchos"],"created_at":"2025-02-16T01:20:49.441Z","updated_at":"2025-12-29T02:32:21.438Z","avatar_url":"https://github.com/markbattistella.png","language":"Swift","funding_links":["https://github.com/sponsors/markbattistella","https://www.paypal.me/markbattistella/5AUD","https://www.paypal.me/markbattistella/10AUD","https://www.paypal.me/markbattistella/20AUD"],"categories":[],"sub_categories":[],"readme":"\u003c!-- markdownlint-disable MD033 MD041 --\u003e\n\u003cdiv align=\"center\"\u003e\n\n# SwiftDataPreviewer\n\n![Swift Versions](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmarkbattistella%2FSwiftDataPreviewer%2Fbadge%3Ftype%3Dswift-versions)\n\n![Platforms](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmarkbattistella%2FSwiftDataPreviewer%2Fbadge%3Ftype%3Dplatforms)\n\n![Licence](https://img.shields.io/badge/Licence-MIT-white?labelColor=blue\u0026style=flat)\n\n\u003c/div\u003e\n\n`SwiftDataPreviewer` is a lightweight Swift package designed to simplify SwiftUI previews using SwiftData. It provides an **in-memory model container** for use in `DEBUG` builds, allowing you to preview your SwiftData-powered views with sample data.\n\n## Features\n\n- **Seamless SwiftData Previews**: Easily inject a `ModelContainer` into your SwiftUI previews.\n- **In-Memory Storage**: Prevents persistent data pollution while testing.\n- **Automatic Sample Data Insertion**: Quickly preview lists and other data-driven views.\n- **Developer-Friendly API**: Just wrap your view with `SwiftDataPreviewer`.\n\n## Installation\n\nAdd `SwiftDataPreviewer` to your Swift project using Swift Package Manager.\n\n```swift\ndependencies: [\n  .package(url: \"https://github.com/markbattistella/SwiftDataPreviewer\", from: \"1.0.0\")\n]\n```\n\nAlternatively, you can add `SwiftDataPreviewer` using Xcode by navigating to `File \u003e Add Packages` and entering the package repository URL.\n\n## Recommended Usage\n\n\u003e [!NOTE]\n\u003e `SwiftDataPreviewer` is designed for SwiftUI previews only and is not meant for production usage. It provides an in-memory `ModelContainer` that is automatically configured for SwiftData-powered views.\n\n## Usage\n\n1. Define a SwiftData Model\n\n   Ensure your SwiftData model conforms to PersistentModel:\n\n    ```swift\n    import SwiftData\n\n    @Model\n    final class Item {\n      var timestamp: Date \n\n      init(timestamp: Date) {\n        self.timestamp = timestamp\n      }\n    }\n    ```\n\n2. Create a Preview Container (optional)\n\n   Define a `PreviewContainer` with the model types you want to include:\n\n    ```swift\n    #if DEBUG\n    import SwiftDataPreviewer\n\n    final class Previewer {\n      let previewContainer = PreviewContainer(Item.self)\n    }\n    #endif\n    ```\n\n3. Use `SwiftDataPreviewer` in Your Previews\n\n   Wrap your SwiftUI view in `SwiftDataPreviewer` and pass sample data:\n\n    ```swift\n    #if DEBUG\n    import SwiftUI\n    import SwiftData\n\n    struct ItemListView: View {\n      @Query private var items: [Item]\n\n      var body: some View {\n        List(items) { item in\n          Text(item.timestamp, style: .date)\n        }\n      }\n    }\n\n    // Pre-Xcode 15\n    struct UserListView_Previews: PreviewProvider {\n      static var previews: some View {\n        SwiftDataPreviewer(\n          preview: Previewer.previewContainer,\n          items: [\n            Item(timestamp: Date()),\n            Item(timestamp: Date()),\n            Item(timestamp: Date()),\n          ]\n        ) {\n          ItemListView()\n        }\n      }\n    }\n\n    // Post-Xcode 15\n    #Preview(\"Array items\") {\n      SwiftDataPreviewer(\n        preview: PreviewContainer(Item.self),\n        items: Item.mockItems\n      ) {\n        ItemListView()\n      }\n    }\n\n    #Preview(\"Single item\") {\n      SwiftDataPreviewer(\n        preview: Previewer.previewContainer,\n        item: Item.mockItem\n      ) {\n        ContentView()\n      }\n    }\n\n   #endif\n   ```\n\n## How It Works\n\n1. PreviewContainer creates an in-memory ModelContainer.\n\n1. SwiftDataPreviewer injects the container into your SwiftUI view.\n\n1. Sample data is automatically inserted so your previews are populated.\n\n## Contributing\n\nContributions are welcome! If you find a bug or have suggestions for improvements, feel free to submit a pull request.\n\n## Licence\n\n`SwiftDataPreviewer` is available under the MIT licence. See the LICENCE file for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkbattistella%2Fswiftdatapreviewer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkbattistella%2Fswiftdatapreviewer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkbattistella%2Fswiftdatapreviewer/lists"}