{"id":25457911,"url":"https://github.com/cuadros-code/project-11-swiftui-book-worm","last_synced_at":"2025-11-02T13:30:26.407Z","repository":{"id":272202996,"uuid":"915448188","full_name":"cuadros-code/Project-11-SwiftUI-book-worm","owner":"cuadros-code","description":"Project 11 book history","archived":false,"fork":false,"pushed_at":"2025-01-16T15:59:48.000Z","size":1864,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-16T16:43:16.827Z","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/cuadros-code.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}},"created_at":"2025-01-11T21:41:31.000Z","updated_at":"2025-01-16T15:59:49.000Z","dependencies_parsed_at":"2025-01-16T16:43:20.495Z","dependency_job_id":"1a7fc42a-a80d-4844-add6-50f9a413a751","html_url":"https://github.com/cuadros-code/Project-11-SwiftUI-book-worm","commit_stats":null,"previous_names":["cuadros-code/porject-11-swiftui-book-worm","cuadros-code/project-11-swiftui-book-worm"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuadros-code%2FProject-11-SwiftUI-book-worm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuadros-code%2FProject-11-SwiftUI-book-worm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuadros-code%2FProject-11-SwiftUI-book-worm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuadros-code%2FProject-11-SwiftUI-book-worm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cuadros-code","download_url":"https://codeload.github.com/cuadros-code/Project-11-SwiftUI-book-worm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239394662,"owners_count":19631122,"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":"2025-02-18T02:19:30.107Z","updated_at":"2025-11-02T13:30:26.217Z","avatar_url":"https://github.com/cuadros-code.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"#  SwiftData\n\n## step by step\n\n- Create model \n```swift\nimport Foundation\nimport SwiftData\n\n@Model\nclass Student {\n    var id: UUID\n    var name: String\n    \n    init(id: UUID, name: String) {\n        self.id = id\n        self.name = name\n    }\n}\n\n```\n\n- Add model container to View\n```swift\n.modelContainer(for: Student.self)\n```\n\n- Use model context and Query to use data from SwiftData\n```swift\nimport SwiftUI\nimport SwiftData\n\nstruct ContentView: View {\n    \n    @Environment(\\.modelContext) var modelContext\n    @Query var students: [Student]\n    \n    var body: some View {\n        NavigationStack {\n            List(students) { student in\n                Text(student.name)\n            }\n            .navigationTitle(\"Classroom\")\n            .toolbar {\n                Button(\"Add\") {\n                    let firstNames = [\"Kevin\", \"Julio\", \"Luz\"]\n                    let lastNames = [\"Mora\", \"Cuadros\", \"Ferrari\"]\n                    \n                    let chosenFirstName = firstNames.randomElement()!\n                    let chosenLastName = lastNames.randomElement()!\n                    \n                    let student = Student(\n                        id: UUID(),\n                        name: \"\\(chosenFirstName) \\(chosenLastName)\"\n                    )\n                    \n                    modelContext.insert(student)\n                    \n                }\n            }\n        }\n    }\n}\n```\n\n- Sort Using Query\n```swift\n@Query(sort: \\Book.rating, order: .forward) var books: [Book]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuadros-code%2Fproject-11-swiftui-book-worm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcuadros-code%2Fproject-11-swiftui-book-worm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuadros-code%2Fproject-11-swiftui-book-worm/lists"}