{"id":22112121,"url":"https://github.com/fourplusone/observed-optional-object","last_synced_at":"2025-09-05T05:48:27.527Z","repository":{"id":46690139,"uuid":"399569954","full_name":"fourplusone/observed-optional-object","owner":"fourplusone","description":"Observe objects in SwiftUI Views which may be nil","archived":false,"fork":false,"pushed_at":"2021-09-21T16:11:35.000Z","size":4,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-04T00:54:15.435Z","etag":null,"topics":["ios","macos","swift","swift-library","swiftui","tvos","watchos"],"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/fourplusone.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":"2021-08-24T18:40:11.000Z","updated_at":"2025-05-06T00:43:02.000Z","dependencies_parsed_at":"2022-08-31T01:01:26.886Z","dependency_job_id":null,"html_url":"https://github.com/fourplusone/observed-optional-object","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/fourplusone/observed-optional-object","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fourplusone%2Fobserved-optional-object","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fourplusone%2Fobserved-optional-object/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fourplusone%2Fobserved-optional-object/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fourplusone%2Fobserved-optional-object/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fourplusone","download_url":"https://codeload.github.com/fourplusone/observed-optional-object/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fourplusone%2Fobserved-optional-object/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273673241,"owners_count":25147508,"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-09-04T02:00:08.968Z","response_time":61,"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":["ios","macos","swift","swift-library","swiftui","tvos","watchos"],"created_at":"2024-12-01T10:56:46.253Z","updated_at":"2025-09-05T05:48:22.511Z","avatar_url":"https://github.com/fourplusone.png","language":"Swift","readme":"# ObservedOptionalObject\n\n[![Swift](https://github.com/fourplusone/observed-optional-object/actions/workflows/swift.yml/badge.svg)](https://github.com/fourplusone/observed-optional-object/actions/workflows/swift.yml)\n\n## Rationale\n\n`SwiftUI`s `@ObservedObject` requires that the observed object actually exists. In some cases\nit's convenient to observe an object which might be nil. In this case, `@ObservedOptionalObject` can be used.\n\n```swift\nstruct SomeView: View {\n    // Instead of\n    @ObservedObject var anObject: Model? // Won't work\n    \n    // use\n    @ObservedOptionalObject var anObject: Model?\n    \n    var body: some View {\n        HStack {\n            Text(\"Name\")\n            if let name = anObject?.name {\n                Text(name)\n            }\n        }\n    }\n}\n```\n\nPlease note, that  `@ObservedOptionalObject` is only useful if your contains content that should\nbe displayed, even when the object is `nil`. Otherwise the view should be contained within an `if let`  statement:\n`if let obj = obj { SomeView(anObject: obj) }`\n\n## Installation\n\nThis package is available via SwiftPM\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/fourplusone/observed-optional-object.git\", \n        .upToNextMinor(from: \"0.1.0\")\n    )\n]\n```\n\n## License\n\nThis project is licensed under the MIT License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffourplusone%2Fobserved-optional-object","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffourplusone%2Fobserved-optional-object","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffourplusone%2Fobserved-optional-object/lists"}